PHP開發劄記-星期/周操作中常用的日期擷取方法_PHP教程

來源:互聯網
上載者:User
本周一
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); //本月一日減一天即是上月最後一日

轉載自http://hi.baidu.com/panez/item/bc88803f487955f2a884289d

http://www.bkjia.com/PHPjc/776509.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/776509.htmlTechArticle本周一 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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.