<?php//本周一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); //本月一日減一天即是上月最后一日
新聞熱點
疑難解答
圖片精選