本文實例講述了php中strtotime函數用法。分享給大家供大家參考。具體如下:strtotime(字符串$時間[,詮釋$現在])int strtotime(string $time [,int $now] 該函數期望得到一個包含美國英語日期格式,并會嘗試解析成一個Unix時間戳(多少秒自1970年1月1日00:00:00星期一該格式),相對于現在提供的時間戳,或當前時間如果現在不提供這個函數將使用TZhtml' target='_blank'>環境變量(如果有)來計算時間戳,自PHP 5.1.0有更容易的方法來確定所使用的所有/日期時間函數的時區,這一過程是解釋在date_default_timezone_get()函數的一頁.解析的字符串,在PHP 5.0.0,不允許在微秒的時間,自PHP 5.0.0他們是允許的,但忽略.現在哪些是作為計算基數相對日期使用時間戳.返回值:在成功返回一個時間戳,否則返回FALSE,前到PHP 5.1.0,這個函數將返回失敗-1.現在我們來看看strtotime字符轉換成時間的函數實例,代碼如下: 復制代碼 代碼如下: php //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i = $nbrweek; $i++) { // 52 week in one year of coursewww.phpfensi.com $nextweek[$i]=date('D d M Y', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin = strtotime('06-05-2010'); //D Day Month Year - like function format. $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Preview for($i = 1; $i = $nbrweek; $i++) { echo ' br - '.$result[$i]; }
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 o F Y h:i:s A', $timestamp); }