Php 7年后
我试图从日期中减去7年 我试过了,但没有成功:(我做错了什么Php 7年后,php,date,strtotime,Php,Date,Strtotime,我试图从日期中减去7年 我试过了,但没有成功:(我做错了什么 strtotime("-7 year", strtotime(date("Y"))) 这将呼应出1131498720我想要的答案是2005 我忘了提到“-7”是一个变量,$x=-7strotime返回一个unix时间戳(自1970年1月1日起的秒数)。1131498720对应于2005年11月8日,也就是过去的7年 既然你只是在减去年数,为什么不简单地 $seven_years_ago = date('Y') - 7; 尝试: 因
strtotime("-7 year", strtotime(date("Y")))
这将呼应出1131498720
我想要的答案是2005
我忘了提到“-7”是一个变量,
$x=-7
strotime返回一个unix时间戳(自1970年1月1日起的秒数)。1131498720对应于2005年11月8日,也就是过去的7年
既然你只是在减去年数,为什么不简单地
$seven_years_ago = date('Y') - 7;
尝试:
因此,在这种情况下,
-$var
不是火箭科学,只是基本的减法。$str=date('Y',strtime('date('Y')。“-”$var.“year”);
正如Marc提到的那样。只要做一个简单的减法,就像Marc的答案一样,因为这是更简单的解决方案。
$str = date('Y', strtotime(date('Y') . " -7year"));
echo $str;