c# - 如何检查当前时区是否为 (UTC+9 :00) Osaka, Sapporo, Tokyo on other languages?

标签 c# .net localization timezone

我可以通过以下方式比较它:

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/

相关文章:

c# - 是否有当前等效于停产的 "SQL Server English Query"

c# - 自定义登录 ASP.NET C#

.net - 即使方法标记为 AllowAnonymous,也会为无效 token 返回 401

c# - ASP.NET MVC : Localization issues (wrong resx file for culture)

ruby-on-rails - Ruby on Rails 自动提取字符串进行翻译

C# 文件 - 在剪贴板中如何设置/读取调用哪个操作 - 剪切或复制

c# - 检索字体的文件名

.net - 将 Windows 服务类添加到类库

c# - 这是我的 child 吗?

android - 支持菲律宾语