原始碼是這樣的
$time1=strtotime(date("Y-m-d H:i:s"));
$time2=strtotime("2014-11-11 00:00:00");
$time3=strtotime("2013-01-01");
$sub1=ceil(($time2-$time1)/3600);
$sub2=ceil(($time3-$time1)/86400);
echo $time2."
";
echo $time1."
";
echo "距離時間$sub1";
?>
最後輸出的結果是
Strict Standards: strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\AppServ\www\base1\strcmp.php on line 18
1415664000
1405231125
距離時間2899
那位大神幫忙解決一下哦
回複討論(解決方案)
你沒有設定時區,或時區代碼是錯誤的
php.ini 中
date.timezone = PRC;北京時間
或程式中
date_default_timezone_set('PRC');
非常感謝感謝你
還有一個問題 本來明明是除以了3600,按理來說應該顯示19小時 可顯示的是2899 這麼多
為啥呢
$time1=strtotime(date("Y-m-d H:i:s")); //這不是今天嗎? 2014-07-13
$time2=strtotime("2014-11-11 00:00:00");
距離 2014-11-11 不是有 120 天嗎?
我說那個顯示的是2899,,怎麼能夠轉化為120天呢
自己根據你算出的時間差進行具體的轉換,就可以實現倒計時的具體時間。
可以大概的參考下這個:
http://blog.csdn.net/u011619326/article/details/37740129