PHP strtotime() 函數(shù)
定義和用法
strtotime() 函數(shù)將任何英文文本的日期時(shí)間描述解析為 Unix 時(shí)間戳。
語法
strtotime(time,now)
參數(shù) | 描述 |
---|---|
time | 規(guī)定要解析的時(shí)間字符串。 |
now | 用來計(jì)算返回值的時(shí)間戳。如果省略該參數(shù),則使用當(dāng)前時(shí)間。 |
說明
該函數(shù)預(yù)期接受一個(gè)包含美國英語日期格式的字符串并嘗試將其解析為 Unix 時(shí)間戳(自 January 1 1970 00:00:00 GMT 起的秒數(shù)),其值相對(duì)于 now 參數(shù)給出的時(shí)間,如果沒有提供此參數(shù),則用系統(tǒng)當(dāng)前時(shí)間。
該函數(shù)將使用 TZ 環(huán)境變量(如果有的話)來計(jì)算時(shí)間戳。自 PHP 5.1.0 起有更容易的方法來定義時(shí)區(qū)用于所有的日期/時(shí)間函數(shù)。此過程在 date_default_timezone_get() 函數(shù)頁面中有說明。
返回值
成功則返回時(shí)間戳,否則返回 FALSE。在 PHP 5.1.0 之前本函數(shù)在失敗時(shí)返回 -1。
例子
<?php echo(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")); ?>
輸出:
1138614504 1128290400 1138632504 1139219304 1139503709 1139180400 1138489200