PHP中strtotime()的使用

strtotime是一个非常强大的函数。

传入的参数,详见官网的介绍

 

本月最后一个周日

echo date('Y-m-d',strtotime('last sunday of this month'));

下个月第三个周日

echo date('Y-m-d',strtotime('third sunday of next month'));

下个月的最后一天

echo date('Y-m-d',strtotime('last day of next month'));

第28周的星期日的日期

date('Y-m-d', strtotime('2014-W28-7'));

注意:

1. 获取本年的最后一天 strtotime('last day of this year') 是不起作用的,因为 last day of 只对月起作用。正确的方法date('Y-m-d',strToTime('1/1 next year -1 day'));

 

另附:

// the first day in this week,it's Monday
$thisMonday = date('Y-m-d', time() - 86400*date('w') + 86400);
// the last day in this week,it's Friday
$thisFriday   = date('Y-m-d', time() - 86400*date('w') + 86400*5);

posted @ 2014-02-17 11:10  飞凡123  阅读(1329)  评论(0编辑  收藏  举报