Linux-Windows 时区映射?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4967903/
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
Linux- Windows Timezone Mapping?
提问by Sathish Guru
All the Timezone in Windows are displayed in such a way like
Windows 中的所有时区都以这样的方式显示
(GMT+10:00) Canberra, Melbourne, Sydney
,
(GMT+10:00) Canberra, Melbourne, Sydney
,
GMT and Offset and the place. In turn , the Linux is having every timezone as directory mapping in /usr/share/zoneinfo/[Continent]/[Place].
GMT 和 Offset 和地方。反过来,Linux 将每个时区作为 /usr/share/zoneinfo/[Continent]/[Place] 中的目录映射。
I am in need of mapping every Windows timezone to the Linux timezone for my application. like
我需要为我的应用程序将每个 Windows 时区映射到 Linux 时区。喜欢
(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi => Asia/Calcutta
Now the problem surface for the International Date Line Westwhich lies between Russia and America. In Windows, its marked by (GMT-12:00) International Date Line West and from various sources I found that in Linux its Etc/GMT+12.
现在,位于俄罗斯和美国之间的国际日期变更线西部的问题浮出水面。在 Windows 中,它以 (GMT-12:00) International Date Line West 为标志,从各种来源我发现在 Linux 中它的 Etc/GMT+12。
(GMT-12:00) International Date Line West => Etc/GMT+12
also
还
(GMT+12:00) Coordinated Universal Time+12 => Etc/GMT-12
(GMT-02:00) Coordinated Universal Time-02 => Etc/GMT+2
(GMT-11:00) Coordinated Universal Time-11 => Etc/GMT+11
This keeps me puzzled and my app works closely with the Timestamp w.r.t UTC and the UTC offset. So this mapping is confusing me and the app.
这让我感到困惑,我的应用程序与时间戳 wrt UTC 和 UTC 偏移量密切相关。所以这个映射让我和应用程序感到困惑。
Can anyone explain why there is a vice versa of -12 and +12 Offset in both for a same place?
谁能解释为什么在同一个地方有 -12 和 +12 Offset 反之亦然?
Thanks in Advance :)
提前致谢 :)
采纳答案by Lennart Regebro
Unicode.org hosts a mapping as part of the CLDR. You can get to the latest version here. There are also XML versions of the data linked from that page.
Unicode.org 将映射作为 CLDR 的一部分进行托管。 您可以在此处获取最新版本。还有从该页面链接的数据的 XML 版本。
You can find example code (in Python) of how to generate a mapping from the XML data here.
您可以在此处找到有关如何从 XML 数据生成映射的示例代码(使用 Python)。
Obligatory Time Zone Rant:
强制性时区咆哮:
Note that whoever implemented the timezone support in Windows was on drugs. I'm not kidding you. Look at the timezone names. Why is Central European time known as "Romance standard Time". Romance? What, because it includes Paris, or? Roman Standard Time could have made sense a it also includes Rome, but Romance!?
请注意,在 Windows 中实现时区支持的人都在吸毒。我不是在逗你。查看时区名称。为什么中欧时间被称为“浪漫标准时间”。浪漫?什么,因为它包括巴黎,或者?罗马标准时间可能是有道理的,因为它也包括罗马,但是浪漫!?
Also, in the registry the timezones are not organized under their id. No, they are, insanely, organized under their display name! Since that is localized, it means every timezone will be located under a different key in different translations of Windows!!! So to find the right timezone, you have to look through all the timezone to see which has the correct id.
此外,在注册表中,时区不在它们的 id 下组织。不,他们疯狂地以他们的显示名称组织!由于这是本地化的,这意味着在 Windows 的不同翻译中,每个时区都将位于不同的键下!!!因此,要找到正确的时区,您必须查看所有时区以查看哪个具有正确的 id。
I have example code of that too here. See the get_win_timezone()
function.
我有这个例子的代码太在这里。见get_win_timezone()
功能。
I wonder if it is the same guy who designed this that decided that POSIX should reverse the sign on timezones, so that -8 hours mean plus8 hours. In any case, I'm sure they were smoking something illegal together.
我想知道是否是设计这个的人决定 POSIX 应该反转时区的符号,所以 -8 小时意味着加上8 小时。无论如何,我敢肯定他们一起吸食非法的东西。
回答by Patrick Echterbruch
The definitions in the Etc
directory are meant to be POSIX style, thus they have their sign reversed from what you would expect. I'm not an expert for POSIX, but as far as I get it, the basic idea was to express timzones by the combination of their local name and the offset to GMT. An example for middle europe (Central European Time / CET):
Etc
目录中的定义是 POSIX 风格的,因此它们的符号与您期望的相反。我不是 POSIX 的专家,但据我所知,基本思想是通过它们的本地名称和 GMT 偏移量的组合来表达 timzones。中欧示例(中欧时间/CET):
Europe/Berlin (w/o daylight savings) equals GMT+01:00 equals CET-1
GMT-1
in the Etc
directory in fact describes a (fictous) timezone called "GMT" which is one hour ahead of (the real) GMT.
GMT-1
在Etc
目录中实际上描述了一个名为“GMT”的(虚构的)时区,它比(真实的)GMT 提前一小时。
As far as I know, these files are only there to allow you to create (symbolic) links against them, so if you were situated somwhere in middle europe, you would create a link to GMT-1
and call it CET-1
.
据我所知,这些文件仅用于允许您针对它们创建(符号)链接,因此,如果您位于中欧的某个地方,您将创建一个链接GMT-1
并将其命名为CET-1
.
The best recommendation I can give you is to entirely ignore the Etc
directory and use some mapping table from windows timezone names to unix timezone folders/files. Windows timezone info does not only give the offset to GMT, but also knows about Daylight Savings (and when in begins or ends). The same is true for the folders/files in the timezone database, but not for the files in the Etc
directory - they give a simple static offset to GMT.
我能给你的最好建议是完全忽略Etc
目录并使用一些从 Windows 时区名称到 unix 时区文件夹/文件的映射表。Windows 时区信息不仅提供格林威治标准时间的偏移量,还知道夏令时(以及何时开始或结束)。时区数据库中的文件夹/文件也是如此,但Etc
目录中的文件则不然——它们为 GMT 提供了一个简单的静态偏移量。
A list of time zones in the tz database can be found in the wikipedia.
可以在 wikipedia 中找到 tz 数据库中的时区列表。
回答by Edwin Buck
If all the files have the signs reversed, then the files you are looking at are forward mapping offsets, while what you are probably more familiar with is reverse mapping offsets.
如果所有文件的符号都反转了,那么您正在查看的文件是正向映射偏移量,而您可能更熟悉的是反向映射偏移量。
Windows typically uses the local timezone for the machine's internal time, so it needs timezone files which can translate back to UTC. Linux typically uses UTC as the machine's internal time, so it needs timezone files which can translate to local time.
Windows 通常使用本地时区作为机器的内部时间,因此它需要可以转换回 UTC 的时区文件。Linux 通常使用 UTC 作为机器的内部时间,因此它需要可以转换为本地时间的时区文件。
Since the offsets for the two machines describe complimentary but opposite directions of time, it stands to reason that the time zone files are inversely related to each other. In other words, if you pick up a set of zone files from one, the other set will be negative.
由于两台机器的偏移量描述了互补但相反的时间方向,因此时区文件彼此成反比是理所当然的。换句话说,如果您从一个文件中提取一组区域文件,则另一组文件将为负数。