The time zone ID 'Gulf Standard Time' was not found on the local computer.
下面是我正在使用的代码行
TimeZoneInfo tZone = TimeZoneInfo.FindSystemTimeZoneById("Gulf Standard Time");
你能否告诉我代码中究竟是什么问题,因为我已经检查了它的正确时区名称 .
1 回答
0
正如评论中指出的那样, "Gulf Standard Time" 不是有效的Windows时区标识符 .
海湾标准时间通常是指UTC 04:00没有DST,如在阿拉伯联合酋长国和阿曼观察到的,as described here . Windows中的相应时区显示为英文显示名称 (UTC+04:00) Abu Dhabi, Muscat ,并且具有相应的ID Arabian Standard Time .
因此在.NET中:
TimeZoneInfo tZone = TimeZoneInfo.FindSystemTimeZoneById("Arabian Standard Time");
Console.WriteLine(tzone.DisplayName);
// prints: (UTC+04:00) Abu Dhabi, Muscat
1 回答
正如评论中指出的那样,
"Gulf Standard Time"
不是有效的Windows时区标识符 .海湾标准时间通常是指UTC 04:00没有DST,如在阿拉伯联合酋长国和阿曼观察到的,as described here . Windows中的相应时区显示为英文显示名称
(UTC+04:00) Abu Dhabi, Muscat
,并且具有相应的IDArabian Standard Time
.因此在.NET中:
要获取支持的时区列表,请在.NET代码中使用
TimeZoneInfo.GetSystemTimeZones()
,并检查Id
和DisplayName
属性 . 或者,您可以在命令行上调用TZUTIL /L
来列出它们 .另外,只是要指出这一切都假设您在Windows上运行 . 如果您实际上在非Windows系统(Linux,OSX等)上运行.NET Core,则应使用IANA时区ID . 在这种情况下,
"Asia/Dubai"
或"Asia/Muscat"
是合适的 .如果您的代码可能在Windows和非Windows系统上运行,那么您将需要利用我的TimeZoneConverter库 .