sta*_*san 33
是的,有:strtotime():
strtotime("-6 months");
strtotime("+2 years");
这些将返回Unix时间戳.所以你可能想把结果放入date()
或localtime()
或gmtime()
.
请不要试图减去6个月或增加2年的秒数time()
.这不会考虑夏令时或闰秒之类的事情,但仍然会以秒为单位给出一个不太可能达到所需精度的值.让库函数做到这一点.
Boo*_*eus 12
像这样:
$date6monthsago = strtotime('-6 months');
$date2year = strtotime('+2 year');
Run Code Online (Sandbox Code Playgroud)
小智 6
根据您的使用选择以下代码..
echo date('m/d/Y',strtotime("-6 months")); //ago 6month o/p 05/23/2011
echo date('d-m-Y',strtotime("6 months")); //comming 6month o/p 23-05-2012
echo date('m.d.Y',strtotime("+2 years")); //comming year o/p 11.23.2013
Run Code Online (Sandbox Code Playgroud)