PHP strtotime() 函數

來源:互聯網
上載者:User
定義和用法

strtotime() 函數將任何英文文本的日期時間描述解析為 Unix 時間戳記。

文法
strtotime(time,now)
參數 描述
time 規定要解析的時間字串。
now 用來計算傳回值的時間戳記。如果省略該參數,則使用目前時間。
說明

該函數預期接受一個包含美國英語日期格式的字串並嘗試將其解析為 Unix 時間戳記(自 January 1 1970 00:00:00 GMT 起的秒數),其值相對於 now 參數給出的時間,如果沒有提供此參數,則用系統目前時間。

該函數將使用 TZ 環境變數(如果有的話)來計算時間戳記。自 PHP 5.1.0 起有更容易的方法來定義時區用於所有的日期/時間函數。此過程在 date_default_timezone_get() 函數頁面中有說明。

傳回值

成功則返回時間戳記,否則返回 FALSE。在 PHP 5.1.0 之前本函數在失敗時返回 -1。

例子
<?phpecho(strtotime("now"));echo(strtotime("3 October 2005"));echo(strtotime("+5 hours"));echo(strtotime("+1 week"));echo(strtotime("+1 week 3 days 7 hours 5 seconds"));echo(strtotime("next Monday"));echo(strtotime("last Sunday"));?>

輸出:

1138614504112829040011386325041139219304113950370911391804001138489200

聯繫我們

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