TimeZoneInfo.GetSystemTimeZones 错误时区(名称) [英] TimeZoneInfo.GetSystemTimeZones wrong timezone (name)

查看:32
本文介绍了TimeZoneInfo.GetSystemTimeZones 错误时区(名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft 定义了一个列表所有时区及其名称.

Microsoft defined a list of all timezones and their name.

例如110 W. 欧洲标准时间 (GMT+01:00) 阿姆斯特丹、柏林、伯尔尼、罗马、斯德哥尔摩、维也纳

E.g. 110 W. Europe Standard Time (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna

时区名称错误,因为它应该是Central 欧洲时间而不是西方.

The name of the timezone is wrong, because it should be Central European Time instead of Western.

也许您知道检索正确时区列表的解决方案?

Perphaps you know a solution to retrieve a correct list of timezones?

推荐答案

一些事情:

  • 您链接到的页面对 Windows Embedded 1.1 有效 - 一种古老且已弃用的产品.该页面仅供历史参考.Microsoft 不维护包含现代 Windows 和 .NET 支持的时区列表的网页,因为随着世界时区因地缘政治变化而更新,这些值经常发生变化.相反,在命令行上使用 .NET 的 TimeZoneInfo.GetSystemTimeZones()tzutil.exe/l.

  • The page you linked to is only valid for Windows Embedded 1.1 - an ancient and deprecated product. That page is for historical reference only. Microsoft does not maintain a web page with the list of time zones supported in modern Windows and .NET, because the values change often as the world's time zones are updated as a result of geopolitical changes. Instead, use .NET's TimeZoneInfo.GetSystemTimeZones(), or tzutil.exe /l on the command line.

您描述的值类似于操作系统语言为英语时在 TimeZoneInfo 对象上返回的 DisplayName 属性.这些值主要用于时区选择 - 即,从可用时区的下拉列表中选择一个时区.因此,Windows 选择为某些时区提供城市名称,而不是更广泛的口语名称.

The value you described is similar to the DisplayName property returned on a TimeZoneInfo object when the OS language is English. These values are primarily for time zone selection - that is, picking a time zone from a drop down list of available time zones. As such, Windows elects to provide city names for some of the time zones, rather than the broader colloquial names.

要获得中欧时间" 之类的值,您需要使用来自Unicode CLDR 项目,或来自使用该数据的库.数据以多种不同的语言提供,因此您需要知道时区的标识符以及您感兴趣的语言/区域设置.

To get a value like "Central European Time", you would need to use data from the Unicode CLDR project, or from a library that consumes that data. The data is given in many different languages, so you will need to know both the identifier of the time zone, and the language/locale that you are interested in.

为 .NET 中的时区提供 CLDR 数据的一个这样的库是 TimeZoneNames -其中我是作者.使用这个库很简单.从 Nuget 安装后,只需调用 TZNames.GetNamesForTimeZone 并传递 IANA 时区标识符或 Windows 时区标识符,以及您感兴趣的语言/区域设置的 IETF 语言标记.项目自述文件中的示例进一步解释.

One such library that gives CLDR data for time zones in .NET is TimeZoneNames - of which I am the author. Using this library is straightforward. Once installed from Nuget, just call TZNames.GetNamesForTimeZone and pass either a an IANA time zone identifier, or a Windows time zone identifier, along with an IETF language tag for the language/locale you are interested in. The samples in the project readme explain further.

这篇关于TimeZoneInfo.GetSystemTimeZones 错误时区(名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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