php把日期轉(zhuǎn)成時(shí)間戳的方法:可以利用strtotime()函數(shù)來實(shí)現(xiàn)。strtotime()函數(shù)可以將任何字符串的日期時(shí)間描述解析為Unix時(shí)間戳,若成功則返回時(shí)間戳,失敗則返回false。
strtotime() 函數(shù)將任何字符串的日期時(shí)間描述解析為 Unix 時(shí)間戳,成功則返回時(shí)間戳,失敗則返回 FALSE。
(推薦教程:php圖文教程)
語法:
int strtotime ( string $time [, int $now = time() ] )
參數(shù):
-
time 必需。規(guī)定日期/時(shí)間字符串。
-
now 可選。規(guī)定用來計(jì)算返回值的時(shí)間戳。如果省略該參數(shù),則使用當(dāng)前時(shí)間。
(視頻教程推薦:php視頻教程)
舉例:
<?php // 設(shè)置時(shí)區(qū) date_default_timezone_set("PRC"); $time = strtotime("2018-01-18 08:08:08"); // 將指定日期轉(zhuǎn)成時(shí)間戳 // 打印當(dāng)前時(shí)間 PHP_EOL 換行符,兼容不同系統(tǒng) echo $time, PHP_EOL; //