我有一个 JSON 文件,其中包含time_zone
范围。它的值如下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 and so on.
我想显示当前时间以及每个给定时区的时间。
我尝试按照以下方法来获取受尊重时区的时间,但它引发了错误。
代码:作品
DateTime timeUtc = DateTime.Now;
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var b = TimeZoneInfo.ConvertTime(timeUtc, cstZone);
Error : The time zone ID 'Central Time (US & Canada)' was not found on the local computer.
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Time (US & Canada)");
var b = TimeZoneInfo.ConvertTime(timeUtc , cstZone);
也尝试过但同样的错误,
var c = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(timeUtc, "Central Time (US & Canada)");
我的问题是,time_zone
值在Central Time (US & Canada), Pacific Time (US & Canada), etc.
格式,我必须处理它以及不同的时区,例如London, Casablanca
。遇到这种情况如何处理。