作者JoeHorn (每天都在公司玩OLG)
看板PHP
标题Re: [请益] mktime()与时区问题
时间Tue Jul 19 02:51:03 2016
※ 引述《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://webptt.com/cn.aspx?n=bbs/PHP/M.1468867868.A.A46.html
2F:→ LPH66: 8/17 是在这范围内所以才会差了一小时 07/19 03:28
3F:推 st1009: 太感谢您了!!我没想到会受到日光节约影响 <3 07/19 10:07