PHP一行代码获取时间戳


获取当天零点时间戳
$today = date('Y-m-d’,time());
$todaytime = strtotime($today);

本周一
echo date('Y-m-d',(time()-((date('w')==0?7:date('w'))-1)*24*3600)); //w为星期几的数字形式,这里0为周日

本周日
echo date('Y-m-d',(time()+(7-(date('w')==0?7:date('w')))*24*3600)); //同样使用w,以现在与周日相关天数算

上周一
echo date('Y-m-d',strtotime('-1 monday', time())); //无论今天几号,-1 monday为上一个有效周未

上周日
echo date('Y-m-d',strtotime('-1 sunday', time())); //上一个有效周日,同样适用于其它星期

本月一日
echo date('Y-m-d',strtotime(date('Y-m', time()).'-01 00:00:00')); //直接以strtotime生成

本月最后一日
echo date('Y-m-d',strtotime(date('Y-m', time()).'-'.date('t', time()).' 00:00:00')); //t为当月天数,28至31天

上月一日
echo date('Y-m-d',strtotime('-1 month', strtotime(date('Y-m', time()).'-01 00:00:00'))); //本月一日直接strtotime上减一个月

上月最后一日
echo date('Y-m-d',strtotime(date('Y-m', time()).'-01 00:00:00')-86400); //本月一日减一天即是上月最后一日

$monday = time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600; 周一
$monday = mktime(0, 0, 0, date('m',$monday), date('d',$monday), date('y',$monday)); 周一0点

posted @ 2017-05-25 10:20  King-  阅读(942)  评论(0编辑  收藏  举报