php使用date和strtotime函數輸出指定日期的方法,datestrtotime_PHP教程

來源:互聯網
上載者:User

php使用date和strtotime函數輸出指定日期的方法,datestrtotime


本文執行個體講述了php使用date和strtotime函數輸出指定日期的方法。分享給大家供大家參考。具體方法分析如下:

在php中date和strtotime函數都是對日期操作的,但是在產生上面date和strtotime是不一樣的,一個是數字日期一個是 Unix 時間戳記了,但我們都可以產生相同的日期,下面來看兩個函數的例子。

php中經常會用到date函數和strtotime函數,這2個函數大家一定並不陌生,今天和大家分享下提示。

strtotime — 將任何英文文本的日期時間描述解析為 Unix 時間戳記
複製代碼 代碼如下:date_default_timezone_set('Asia/Shanghai');
//計算昨天的時間,我們用:
date("Ymd",time()-3600);
//產生昨天的時間
date("Ymd",strtotime('yesterday'));
date("Ymd",strtotime('-1 day'));
//產生前天的時間
date("Ymd",strtotime('yesterday -1 day'));
date("Ymd",strtotime('-2 day'));
//產生3天之後的時間
date("Ymd",strtotime('+3 day'));
//產生一個月前的時間
date("Ymd",strtotime('-1 month'));
//產生下個月最後一天的時間
date("Ymd",strtotime('last day of next month'));
//下個周的星期一
date("Ymd",strtotime('next monday'));

希望本文所述對大家的PHP程式設計有所協助。

http://www.bkjia.com/PHPjc/911908.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/911908.htmlTechArticlephp使用date和strtotime函數輸出指定日期的方法,datestrtotime 本文執行個體講述了php使用date和strtotime函數輸出指定日期的方法。分享給大家供大家參...

  • 聯繫我們

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