PHP時間轉(zhuǎn)換函數(shù)
在PHP中時間轉(zhuǎn)換函數(shù)是“strtotime()”,該函數(shù)的作用是將任何英文文本的日期或時間描述解析為Unix時間戳,其語法為“strtotime(time,now)”,該函數(shù)成功則返回時間戳,否則返回FALSE。
簡單例子
<?php echo strtotime("now"), "n"; echo strtotime("10 September 2000"), "n"; echo strtotime("+1 day"), "n"; echo strtotime("+1 week"), "n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "n"; echo strtotime("next Thursday"), "n"; echo strtotime("last Monday"), "n"; ?>
失敗檢查
<?php $str = 'Not Good'; // previous to PHP 5.1.0 you would compare with -1, instead of false if (($timestamp = strtotime($str)) === false) { echo "The string ($str) is bogus"; } else { echo "$str == " . date('l dS of F Y h:i:s A', $timestamp); } ?>
推薦教程:《PHP教程》