php UTC 是否遵守夏令时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5495803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does UTC observe daylight saving time?
提问by 0001
I am trying to write a script where i want to convert any timezone to UTC
and reverse.
But from some where i came to know that while converting any timezone to UTC
with or without DST consideration it will give the same UTC
time.
For example:
If i try to convert this one:
我正在尝试编写一个脚本,我想将任何时区转换为UTC
和反转。但是从某些地方我开始知道,在将任何时区转换为UTC
考虑或不考虑 DST时,它会给出相同的UTC
时间。例如:如果我尝试转换这个:
$mytime = '2011-03-31 05:06:00.000';
$myzone = 'America/New_York';
to UTC with DST and without DST,i will get ..
到带有 DST 和不带 DST 的 UTC,我会得到 ..
(New_York->UTC DST=Yes)2011-03-31 09:06:00
(New_York->UTC DST=No)2011-03-31 09:06:00 ..........
Is this corect ??If yes then why??? Please anybody give me your answers.
这是正确的吗??如果是,那为什么???请任何人给我你的答案。
回答by Jon Skeet
No, UTC itself never has DST. It is the constant frame of reference other time zones are expressed relative to.
不,UTC 本身从来没有 DST。它是相对于其他时区表示的恒定参考框架。
From the Wikipedia UTC page:
UTC does not change with a change of seasons, but local time or civil time may change if a time zone jurisdiction observes daylight saving time or summer time. For example, UTC is 5 hours ahead of local time on the east coast of the United States during winter, but 4 hours ahead during summer.
UTC 不会随着季节的变化而变化,但如果时区管辖区遵守夏令时或夏令时,则当地时间或民用时间可能会发生变化。例如,UTC 在美国东海岸冬季比当地时间早 5 小时,而在夏季则比当地时间早 4 小时。
In other words, when a time zone observes DST, its offset from UTC changes when there's a DST transition, but that's that time zoneobserving DST, not UTC.
换句话说,当一个时区观察 DST 时,当发生 DST 转换时,它与 UTC 的偏移量会发生变化,但那是观察 DST的时区,而不是 UTC。
Without knowing much about PHP time zone handling, it seems strange to me that you can specify "with DST" or "without DST" in a conversion - the time zones themselves specify when DST kicks in... it shouldn't have to be something you specify yourself.
在不太了解 PHP 时区处理的情况下,您可以在转换中指定“带 DST”或“不带 DST”对我来说似乎很奇怪 - 时区本身指定 DST 何时开始......它不应该是你自己指定的东西。
回答by MattFiler
I'm having the same issue, using this code:
我有同样的问题,使用此代码:
date_default_timezone_set('UTC');
$nowdate = date('l jS \of F Y h:i:s A');
echo "Current date and time is: " . $nowdate;
It is summer now, and the time this code produces is one hour behind - so I don't think that UTC time in PHP adjusts to DST.
现在是夏天,这段代码产生的时间晚了一个小时 - 所以我认为 PHP 中的 UTC 时间不会调整为 DST。
Be interesting to see if anyone has the solution...
很有趣,看看是否有人有解决方案......
EDIT:
编辑:
Found this code on a forum, works perfectly!!
在论坛上找到此代码,完美运行!!
date_default_timezone_set('Europe/London');
$TIME = date("m/d/Y H:i",time());
So you can then call the current date and time by using $TIME. The output can be adjusted to display it differently by changing the bit inside the date() tag. If you want to adjust the date() output, use this guide: http://php.net/manual/en/function.time.php
因此,您可以使用 $TIME 调用当前日期和时间。通过更改 date() 标签内的位,可以调整输出以不同方式显示它。如果要调整 date() 输出,请使用本指南:http: //php.net/manual/en/function.time.php
Hope this helps :)
希望这可以帮助 :)