我可以通过以下方式比较它:
if (TimeZoneInfo.Local.ToString().Contains("Tokyo"))
{
//do something ...
}
但问题是,如果我使用日语 native 操作系统,则返回字符串使用日语字符而不是“Osaka, Sapporo, Tokyo”。在我的情况下,我检查了字符串是否包含字符串“Tokyo”,因此,我的代码将无法在日文操作系统上运行。
关于如何解决这个问题的任何想法? 谢谢。
最佳答案
我认为您应该能够使用 TimeZoneInfo.Id
property .我不认为它会被本地化,因为它必须匹配一些注册表项。
In Windows XP and Windows Vista, it corresponds to the subkeys of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone branch of the registry. It can be passed as a parameter to the FindSystemTimeZoneById method to retrieve a particular time zone from the registry.
如果由于某种原因不起作用,也许是 BaseUtcOffset
property对你来说就足够了。
关于c# - 如何检查当前时区是否为 (UTC+9 :00) Osaka, Sapporo, Tokyo on other languages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15779146/