我有一个进程接受datetime值和timezone作为字符串(数据来自外部系统).我需要将此日期时间转换为本地机器时区的时间.
示例代码:
string cetId = "Central European Standard Time";
if (timeZone == "CET")
{
TimeZoneInfo cetZone = TimeZoneInfo.FindSystemTimeZoneById(cetId);
returnDateTime = TimeZoneInfo.ConvertTime(statusDateTime, cetZone, TimeZoneInfo.Local);
}
else if (timeZone == "CEST")
{
TimeZoneInfo cestZone = TimeZoneInfo.FindSystemTimeZoneById(cetId);
returnDateTime = TimeZoneInfo.ConvertTime(statusDateTime, cestZone, TimeZoneInfo.Local);
}
Run Code Online (Sandbox Code Playgroud)
如果时间是CEST(欧洲中部夏令时)而不是CET(欧洲中部时间)或者.net TimeZoneInfo对象处理那个场景,我是否需要做任何特定的事情?