使用ISO 8601日期转换的php字符串的可能原因再增加一个小时(Possible causes for php string with ISO 8601 date conversion adds

编程入门 行业动态 更新时间:2024-10-28 17:14:46
使用ISO 8601日期转换的php字符串的可能原因再增加一个小时(Possible causes for php string with ISO 8601 date conversion adds one more hour)

基本上我有这个:

$data_start = '2012-06-07T13:00:00Z'; if (($timestamp = strtotime($data_start)) === false) { return "The string ($data_start) is bogus"; } else { return "$data_start == " . date('l dS \o\f F Y H:i:s', $timestamp); }

它正在回归:

"Thursday 07th of June 2012 14:00:00"

为什么在strtotime增加1个小时!? 与时区有什么关系?

Basically I've got this:

$data_start = '2012-06-07T13:00:00Z'; if (($timestamp = strtotime($data_start)) === false) { return "The string ($data_start) is bogus"; } else { return "$data_start == " . date('l dS \o\f F Y H:i:s', $timestamp); }

And it is returning:

"Thursday 07th of June 2012 14:00:00"

Why on earth is strtotime adding 1 more hour!? Anything to do with timezones?

最满意答案

$ data_start上的最后一个Z表示日期是UTC时间。 我想你的当地时区是UTC +1?

如果你想一直使用UTC时间,你可以使用类似:date_default_timezone_set('UTC')来绕过你当地的时区设置

the last Z on $data_start tells that the date is in UTC time. I suppose your local timezone is UTC +1 ?

if you want to always work with UTC time, you can use something like : date_default_timezone_set ('UTC') to bypass your local timezone setting

更多推荐

本文发布于:2023-07-30 01:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   原因   日期   小时   ISO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!