看板 PHP 關於我們 聯絡資訊
※ 引述《st1009 (前端攻城師)》之銘言: : 不才在下使用時間函式mktime()遇到問題,不太懂,希望可以得到各位先進解答>.< : [略] 您遇到的問題,關鍵是 "日光節約時間"。 不知道為什麼您會認為"錯誤",但我想下面這段程式可以幫您確認 PHP 的行為。 若是您的資料有跨時區存取/計算的考量,建議用 GMT/UTC 相關 functions。 <?php echo "* Before tz setting" . PHP_EOL; echo date_default_timezone_get() . PHP_EOL; $the_time = mktime(1,1,1,8,17,1959); $the_standard = mktime(1,1,1,7,10,2016); echo '$the_time ='.$the_time. PHP_EOL; echo '$the_standard = '.$the_standard . PHP_EOL; echo date('Y-m-d H:i:s', $the_time) . PHP_EOL; date_default_timezone_set('Asia/Taipei'); echo "* After tz setting" . PHP_EOL; echo date_default_timezone_get() . PHP_EOL; $the_time = mktime(1,1,1,8,17,1959); $the_standard = mktime(1,1,1,7,10,2016); echo '$the_time ='.$the_time. PHP_EOL echo '$the_standard = '.$the_standard . PHP_EOL; echo date('Y-m-d H:i:s', $the_time) . PHP_EOL; /* 結果應該是這樣: * Before tz setting Asia/Chongqing $the_time =-327481139 $the_standard = 1468083661 1959-08-17 01:01:01 * After tz setting Asia/Taipei $the_time =-327484739 $the_standard = 1468083661 1959-08-17 01:01:01 -- ▄▆▇▍ ▆ ▇ ▏▎▍▌▋▊▉ φkaishin ┼── █▏── ▁▁▍▁ ─────── JoeHorn┬┼ ▄ꈠ ▂▄▎ ▄ ▎▄▅ └┼ ┼┐ ◢▂ ▄▆ ┼┴ -▂▄-──-─┼ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.179.219 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1468867868.A.A46.html
LPH66: http://tinyurl.com/jgoampv 台灣在 1959 確實有過日光節約 07/19 03:28
LPH66: 8/17 是在這範圍內所以才會差了一小時 07/19 03:28
st1009: 太感謝您了!!我沒想到會受到日光節約影響 <3 07/19 10:07