MySQL 时区 America/Los_Angeles 和 US/Pacific 以及 PST8PDT 之间的差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4309030/
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
Difference between timezones America/Los_Angeles and US/Pacific and PST8PDT?
提问by Tauren
I need to convert a bunch of dates in a MySQL database from Pacific time (America/Los_Angeles) to UTC. I found a great SO answeron how to do this.
我需要将 MySQL 数据库中的一堆日期从太平洋时间 (America/Los_Angeles) 转换为 UTC。我找到了一个很好的关于如何做到这一点的答案。
During my tests and preparation, I'm finding that I'm getting the same time conversions when using any of the following time zone names:
在我的测试和准备过程中,我发现在使用以下任何时区名称时,我得到了相同的时间转换:
- America/Los_Angeles
- US/Pacific
- PST8PDT
- 美国/洛杉矶
- 美国/太平洋
- PST8PDT
So my questions are the following:
所以我的问题如下:
- Are these all just aliases to the same thing? Or are there actual differences between them at some point in time?
- If I want to provide a list of timezones to users on a website, would it be better to give them selections from the
America
group of names, or theUS
group of names?
- 这些都只是同一事物的别名吗?或者它们在某个时间点之间是否存在实际差异?
- 如果我想向网站上的用户提供时区列表,让他们从
America
名称US
组或名称组中进行选择会更好吗?
采纳答案by deceze
US/Pacific and PST8PDT both belong to the "other" timezones, which come with this warning:
US/Pacific 和 PST8PDT 都属于“其他”时区,带有以下警告:
Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons.
请不要使用此处列出的任何时区(UTC 除外),它们仅出于向后兼容的原因而存在。
They should all refer to the same timezone, compare:
它们都应该指同一个时区,比较:
http://www.travelmath.com/time-zone/PST8PDT
http://www.travelmath.com/time-zone/US/Pacific
http://www.travelmath.com/time-zone/America/Los_Angeles
http://www.travelmath.com/time-zone/PST8PDT
http://www.travelmath.com/time-zone/US/Pacific
http://www.travelmath.com/time-zone/America/Los_Angeles
As such, you should use America/Los_Angeles, which incidentally should also be a pretty "natural" and easy thing to select for users.
因此,您应该使用 America/Los_Angeles,顺便说一句,这也应该是一个非常“自然”且易于为用户选择的东西。
回答by MikeD
I ran into an issue with the parallel US/Eastern
, Americas/New_York
, and EST5EDT
. Here is what I discovered.
我遇到了一个问题,与并行US/Eastern
,Americas/New_York
和EST5EDT
。这是我发现的。
For dates after the Uniform Time Act of 1966went into effect in 1967, these timezones are all identical. Also the US enforced standard DST rules during the World Wars, so they are all identical 1918-1919 and 1942-1945.
对于1966 年统一时间法于 1967 年生效之后的日期,这些时区都是相同的。此外,美国在世界大战期间执行了标准的夏令时规则,因此它们在 1918-1919 和 1942-1945 期间都是相同的。
For any date before 1918, between 1920 and 1941 inclusive, and between 1946 and 1966 inclusive, EST5EDT
will always be identical to EST
. PST8PDT
will always be identical to PST.
对于 1918 年之前、1920 年和 1941 年(含)以及 1946 年和 1966 年(含)之间的任何日期,EST5EDT
将始终与 相同EST
。PST8PDT
将始终与 PST 相同。
Prior to 1967, Americas/New_York
will provide the time as observedin New York City. So Daylight Savings Time will follow the rules in place by the NYC municipal or NY state government. Any date before 1883 Nov 18 12:03:58 will be in local mean timewith an offset of -4:56:02 from UTC. For Americas/Los_Angeles
any time before 1883 Nov 18 12:07:02 will be local mean timewith an offset of -7:52:58 from UTC
. Between 1883 and 1967, Los Angeles follows the LA and California Daylight Savings rules.
1967 年之前,Americas/New_York
将提供在纽约市观察到的时间。因此,夏令时将遵循纽约市或纽约州政府制定的规则。1883 年 11 月 18 日 12:03:58 之前的任何日期都将采用本地平均时间,与 UTC 的偏移量为 -4:56:02。对于Americas/Los_Angeles
1883 年 11 月 18 日 12:07:02 之前的任何时间,都将是本地平均时间,偏移量为 -7:52:58 UTC
。1883 年至 1967 年间,洛杉矶遵循洛杉矶和加利福尼亚的夏令时规则。
Odd things can happen if you have multiple systems where one assumes PST8PDT
and the other assumes Americas/Los_Angeles
. Data might look fine for anything recent. A birthdate for example, from the summer of 1966 might get moved an hour, then truncated so it appears to be on the prior day.
如果您有多个系统,其中一个假设PST8PDT
而另一个假设,则可能会发生奇怪的事情Americas/Los_Angeles
。对于最近的任何数据,数据可能看起来不错。例如,从 1966 年夏天开始的生日可能会移动一个小时,然后被截断,使其看起来是前一天。
And just for extra fun if you are dealing with old dates in Alaska, you need to remember that Alaska was Purchased from Russia. Dates before 1867 Oct 18 are on the other side of the international date line and use the Julian, not Gregorian Calendar. So Juneau, for example, went from 6 Oct 1867 (Julian) +15:02:19 to 18-Oct-1867 (Gregorian) -8:57:41.
如果您正在处理阿拉斯加的旧日期,只是为了额外的乐趣,您需要记住阿拉斯加是从俄罗斯购买的。1867 年 10 月 18 日之前的日期位于国际日期变更线的另一侧,使用儒略历,而不是公历。例如,朱诺从 1867 年 10 月 6 日(朱利安)+15:02:19 到 1867 年 10 月 18 日(格里高利)-8:57:41。
回答by Kelvin
US/Pacific
is a "link" to America/Los_Angeles
in the IANA database (see wikipedia). On Linux systems I've seen, the former is a hard linked file to the latter; on OS X it might be a copy. If you run a checksum (e.g. md5 or sha1) on the entries in /usr/share/zoneinfo/
the 2 should match.
US/Pacific
是America/Los_Angeles
IANA 数据库中的“链接” (请参阅维基百科)。在我见过的 Linux 系统上,前者是后者的硬链接文件;在 OS X 上,它可能是一个副本。如果您/usr/share/zoneinfo/
对 2 中的条目运行校验和(例如 md5 或 sha1),则应该匹配。
However, PST8PDT
may be different - I haven't figured out exactly how. This bug reportindicates that it doesn't track the history of daylight-saving changes, i.e. that it just retroactively applies the current DST rules to the past; but that doesn't seem to be the case in this ruby example. If it were retroactively applying the current rules, both would be -0700
:
但是,PST8PDT
可能会有所不同 - 我还没有弄清楚到底是怎么回事。这个错误报告表明它不跟踪夏令时更改的历史,即它只是追溯地将当前的 DST 规则应用于过去;但在这个 ruby 示例中似乎并非如此。如果追溯应用当前规则,则两者都是-0700
:
> ENV['TZ']='PST8PDT'
> [Time.mktime(2006, 4, 2, 1, 59, 59), Time.mktime(2006, 4, 2, 2)]
=> [2006-04-02 01:59:59 -0800, 2006-04-02 03:00:00 -0700]
On this messagethere's a quote from the original database maintainer. The message author explains that the legacy zones including PST8PDT
used to have obsolete info, but now are "less incorrect" whatever that means.
在这条消息上引用了原始数据库维护者的一句话。消息作者解释说,包括旧版区域在内的信息PST8PDT
曾经具有过时的信息,但现在无论这意味着什么都“不那么不正确”。
To sum up, don't use PST8PDT
, but it should be safe to use either US/Pacific
or America/Los_Angeles
.
总而言之,不要使用PST8PDT
,但使用US/Pacific
或应该是安全的America/Los_Angeles
。