php判斷是不是時間格式的方法:通過strtotime函數(shù)判斷是否是時間格式,語法為【int strtotime ( string $time [,int $now = time()])】,成功則返回時間戳,否則返回FALSE。
【相關(guān)學(xué)習(xí)推薦:php編程(視頻)】
php判斷是不是時間格式的方法:
可以通過strtotime函數(shù)判斷是否是時間格式
function isDateTime($dateTime){ $ret = strtotime($dateTime); return $ret !== FALSE && $ret != -1; }
strtotime函數(shù)用法如下:
strtotime 將任何英文文本的日期時間描述解析為 Unix 時間戳
int strtotime ( string $time [, int $now = time() ] )
本函數(shù)預(yù)期接受一個包含美國英語日期格式的字符串并嘗試將其解析為Unix 時間戳(自 January 1 1970 00:00:00 GMT 起的秒數(shù)),其值相對于now 參數(shù)給出的時間,如果沒有提供此參數(shù)則用系統(tǒng)當(dāng)前時間。
-
time:日期/時間字符串
-
now:用來計算返回值的時間戳
返回值:
成功則返回時間戳,否則返回 FALSE;在 PHP 5.1.0之前本函數(shù)在失敗時返回 -1。
想了解