- 论坛徽章:
- 0
|
php中挺好用的strtotime方法
在PHP中,经常要对日期进行计算,比如要计算一个月前的日期,那么其实最快的方法
是用strtotime,其功能很丰富,如下:
Java代码- 1.echo strtotime("now"), "\n";
- 2.echo strtotime("10 September 2000"), "\n";
- 3.echo strtotime("+1 day"), "\n";
- 4.echo strtotime("+1 week"), "\n";
- 5.echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
- 6.echo strtotime("next Thursday"), "\n";
- 7.echo strtotime("last Monday"), "\n";
复制代码 看到没 +1 day +1 week,马上求出1天后,1个星期后的日期了,
求1个月前,可以:- echo date('Y-m-d', strtotime('1 month ago'))
复制代码 因此,判断是否一个月前,可以- if strtotime($my_date) < strtotime('1 month ago'))
复制代码 |
|