为什么strtotime在不同的时区会给出不同的结果? [英] Why does strtotime give different result in different timezone?

查看:171
本文介绍了为什么strtotime在不同的时区会给出不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么即使给定了相同的日期参数,PHP中的strtotime()为什么在不同的时区也返回不同的结果,有人知道答案吗?我也想知道,我是否可以使用另一个在不同时区提供相同结果的函数来执行类似的任务(将datetime转换为int以轻松地进行计算)?

I am not sure why strtotime() in PHP returns different result in different timezone even though same date is given as parameter, does anyone know the answer? I also want to know, can I do similar task (converting a datetime to an int to do calculations easily) with another function which gives same result across different timezone?

一个例子: 如果我使用strtotime('2011-09-19 00:00:00'),它不应该以秒为单位返回'January 1 1970 00:00:00''2011-09-19 00:00:00'之间的差吗?为什么时区在这里成为问题?我能得到没有时区问题的区别吗?

An example: If I use strtotime('2011-09-19 00:00:00') shouldn't it just return the difference between 'January 1 1970 00:00:00' and '2011-09-19 00:00:00' in seconds ? Why timezone is an issue here? And can I get something which gives just difference without timezone issue?

推荐答案

简而言之:之所以考虑时区,是因为在GMT中考虑了Unix Epoch值.

In short: time zone is considered because the Unix Epoch value is considered in GMT.

从广义上讲,2011-09-19 00:00:00几乎是在格林尼治标准时间区的2011-09-19 00:00:00 6小时后到达孟加拉国的.由于此间隔,当同一日期出现在BD中时,又在GMT区域中经过了21600秒.

In broader sense 2011-09-19 00:00:00 comes to Bangladesh almost after 6 hours it is 2011-09-19 00:00:00 in GMT zone. Because of this gap, another 21600 seconds have passed in the GMT zone when the same date appears in BD.

由于已针对GMT进行了计算,因此您必须添加这些21600秒以获取实际差异.

Since the calculation is done in respect to the GMT, you have to add these 21600 seconds to get the actual difference.

这篇关于为什么strtotime在不同的时区会给出不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆