php字符串轉時間戳
在php中可以使用“strtotime()”函數(shù)將字符串轉為時間戳。
strtotime說明和用法
strtotime 將任何字符串的日期時間描述解析為 Unix 時間戳
strtotime ( string $time [, int $now = time() ] ) : int
本函數(shù)預期接受一個包含美國英語日期格式的字符串并嘗試將其解析為 Unix 時間戳(自 January 1 1970 00:00:00 GMT 起的秒數(shù)),其值相對于 now 參數(shù)給出的時間,如果沒有提供此參數(shù)則用系統(tǒng)當前時間。
本函數(shù)將使用 TZ 環(huán)境變量(如果有的話)來計算時間戳。自 PHP 5.1.0 起有更容易的方法來定義時區(qū)用于所有的日期/時間函數(shù)。此過程在 date_default_timezone_get() 函數(shù)頁面中有說明。
strtotime參數(shù)
time:日期/時間字符串。正確格式的說明詳見 日期與時間格式。
now:用來計算返回值的時間戳。
strtotime返回值
成功則返回時間戳,否則返回 FALSE。在 PHP 5.1.0 之前本函數(shù)在失敗時返回 -1。