我正在安排一项服务,该服务计划在特定时间运行,如下所示
<add key="ScheduledTime" value="18:00" />
我正在尝试将其转换为PST
区域,如下所示
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
scheduledTime = TimeZoneInfo.ConvertTime(DateTime.Parse("18:00"), cstZone);
但我仍然得到我的系统日期而不是PST可以有人告诉我我做错了以下工作时我有以下代码
DateTime timeUtc = DateTime.UtcNow;
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTime(timeUtc, cstZone);
Console.WriteLine("The date and time are {0} {1}.", cstTime, cstZone.IsDaylightSavingTime(cstTime) ? cstZone.DaylightName : cstZone.StandardName);
这就是我所拥有的
DateTime timeUtc = DateTime.UtcNow;
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
DateTime cstTime = TimeZoneInfo.ConvertTime(timeUtc, cstZone);
Console.WriteLine("The date and time are {0} {1}.",cstTime,
cstZone.IsDaylightSavingTime(cstTime) ? cstZone.DaylightName : cstZone.StandardName);
DateTime cst = TimeZoneInfo.ConvertTime(DateTime.Parse("18:00"), cstZone);
Console.Write(cst);
答案 0 :(得分:0)
服务的时区可能不是您所期望的。打印并检查:
Console.WriteLine(TimeZoneInfo.Local);