標籤:sunday mktime 星期幾 時間 mon 今天 strtotime 相關 ==
擷取當天零點時間戳記
$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點
PHP一行代碼擷取時間戳記