php中倒計時的問題

來源:互聯網
上載者:User
原始碼是這樣的

$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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.