-
如果当前日期为
2016-5-31, 用date('Y-m-d', strtotime('-1 month'))会产生错误。因为这里把-1 month按照-30 days来算date('Y-m-d', strtotime('2016-05-31 -1 month'))=2016-05-01date('Y-m-d', strtotime('2016-01-31 +1 month'))=2016-03-02
如果需要取当前月的前后月份的话,需要小心,正确做法可以改为date('m', strtotime(date('Y-m-1').' -1 month')) -
取得当前时间的上一周时间用
date('Y-m-d', strtotime('-1 week'))没有问题,因为每周时间固定为7天。 -
date('m', strtotime(date('Y-m-1').' +1 month')) -
-
echo date("Y-m-d",strtotime('-1 week last monday'))." 00:00:00";echo date("Y-m-d",strtotime('last sunday'))." 23:59:59"; -
echo ‘<br>上周起始时间:<br>‘;
echo date(“Y-m-d H:i:s”,mktime(0, 0 , 0,date(“m”),date(“d”)-date(“w”)+1–7,date(“Y”))),“\n”;
echo date(“Y-m-d H:i:s”,mktime(23,59,59,date(“m”),date(“d”)-date(“w”)+7–7,date(“Y”))),“\n”;
暂无评论