duanfazhun0383
2010-09-21 17:56
浏览 76
已采纳

php mktime for epoch返回-3600,而不是0

If I run the following in PHP:

echo mktime(0,0,0,1,1,1970);

the returned value is -3600, not 0 as I expected.

The server is UK based, it's currently 21 Sep (i.e. BST summertime) (though I wouldn't expect this to affect the epoch timestamp) and per php.info: "Default timezone Europe/London".

Setting the daylight saving time flag also, as follows, gives:

echo mktime(0,0,0,1,1,1970,0); (i.e. the correct DST flag, 0 as 1 Jan not DST/BST) returns -3600

echo mktime(0,0,0,1,1,1970,1); (the incorrect flag - setting 1 Jan as DST) returns -7200

echo mktime(0,0,0,1,1,1970,-1); (i.e. DST flag not set - left to PHP to decide) returns -3600

Does anyone know why the epoch would be returned as -3600, not 0, please?

图片转代码服务由CSDN问答提供 功能建议

如果我在PHP中运行以下命令:

echo mktime(0, 0,0,1,1,1970);

返回的值是-3600,而不是我预期的0。

服务器是英国 基于,它目前是9月21日(即BST夏令时)(虽然我不希望这会影响纪元时间戳)和每个php.info:“默认时区欧洲/伦敦”。

如下设置夏令时标志,给出:

echo mktime(0,0,0,1,1,1970,0); (即正确的DST标志,0表示1月1日而不是DST / BST) returns -3600

echo mktime(0,0,0,1,1,1970,1); (错误的标志 - 将1月1日设置为DST) returns -7200

echo mktime(0,0,0,1,1,1970,-1); (即DST标志未设置 - 由PHP决定) returns -3600

有谁知道为什么这个纪元将被返回-3600而不是0,请?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzun9958 2010-09-21 18:00
    已采纳

    When it was midnight on Jan 1st 1970 in British Summer Time, it was one hour to midnight in Greenwich Mean Time. Try setting the time zone to UTC instead:

    date_default_timezone_set('UTC'); // or just change php.ini
    
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题