ci
Lv 4
ci asked in 電腦與網際網路程式設計 · 1 decade ago

php6 date()函數的問題

我想顯示系統的訊息,寫了一段程式:

<?php

$today=date("l");

echo "$today";

?>

輸出後,卻出現錯誤訊息:

Strict Standards: date() [function.date]: 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:\php\AppServ\www\date.php on line 2

Tuesday

請問出了什麼問題

要怎麼樣顯示正確的星期

Update:

請不要告訴我用@控制,我想知道是什麼問題

Update 2:

所以請設定date.timezone為asia/taipei

無效耶

to流浪玩家 請問還有什麼更好的方法

4 Answers

Rating
  • 1 decade ago
    Favorite Answer

    它有顯示出你要的星期資訊哦~~~

    Strict Standards: date() [function.date]: 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_timezon e_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:\php\AppServ\www\date.php on line 2

    Tuesday

    至於前半段那一整段的訊息則是在告訴你,你使用了系統的時區,這在 php 5 以上的版本視為不安全、有疑慮的,相關的訊息你可以參考一下 PHP Manual 裡關於 date function 的說明。

    Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT message if using the system settings or the TZ environment variable. See also date_default_timezone_set()

    要避免此段訊息的出現,你可以直接在 date 函式裡傳入 timestamp 參數,或是使用 date_default_timezon e_set() 設定要使用的時區。

  • ci
    Lv 4
    1 decade ago

    謝謝

  • Terry
    Lv 5
    1 decade ago

    error_reporting (E_ERROR);

    加這個在前面就只會秀錯誤而不會秀警告了喔

    http://tw.php.net/manual/en/function.error-reporti...

  • 1 decade ago

    這各問題看起來像是php.ini的date.timezone未設定!

    因為此設定於PHP5引入,

    但是PHP5並不會回報錯誤,

    而PHP6在這裡更加嚴格!

    所以請設定date.timezone為asia/taipei。

    不過也可以試試date_default_timezone_set

    Source(s): 自己與Google
Still have questions? Get your answers by asking now.