php一行代碼擷取本周一,本周日,上周一,上周日,本月一日,本月最後一日,上月一日,上月最後一日日期

來源:互聯網
上載者:User
 
 
<?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())); //上一個有效周日,同樣適用於其它星期//上周周一至上周周末$time = time();$last_monday = date('Ymd', strtotime('-1 monday', $time));$last_sunday = date('Ymd', strtotime('-1 sunday', $time));if ($last_monday>$last_sunday){  $last_monday = date('Ymd', strtotime('-2 monday', $time));}echo $last_monday;echo $last_sunday;//本月一日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); //本月一日減一天即是上月最後一日s


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.