相关疑难解决方法(0)

如何在Windows和IANA时区之间进行转换?

时区标签wiki中所述,有两种不同的时区样式.

  • Microsoft提供的用于Windows和.Net TimeZoneInfo类的那些由诸如的值标识"Eastern Standard Time".

  • IANA在TZDB中提供的内容由诸如此类的值标识TimeZoneInfo.

许多基于Internet的API使用IANA时区,但由于多种原因,可能需要将其转换为Windows时区ID,反之亦然.

如何在.Net中实现这一目标?

.net c# timezone nodatime

138
推荐指数
3
解决办法
5万
查看次数

在 C# 中获取特定时区的日期时间时出现 System.TimeZoneNotFoundException 错误

我有一个带有time_zone参数的 JSON 文件。它具有诸如等值London, Casablanca, Arizona, Pacific Time (US & Canada)。基于time_zone,我想获得该DateTime时区的结果。

例如,

Current time = 8/3/2015 4:00:00 PM

If time_zone = Central Time (US & Canada) then result should be 8/3/2015 3:00:00 PM,

If time_zone = Pacific Time (US & Canada) then result should be 8/3/2015 1:00:00 PM,

If time_zone = London then result should be 8/3/2015 9:00:00 PM 等等。

我想显示当前时间以及每个给定时区的时间。

我尝试了以下方法来为受尊重的时区争取时间,但它引发了错误。

代码:作品

 DateTime timeUtc = DateTime.Now;
 TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); …
Run Code Online (Sandbox Code Playgroud)

c# timezone

16
推荐指数
3
解决办法
3万
查看次数

标签 统计

c# ×2

timezone ×2

.net ×1

nodatime ×1