[06-17] TimeZoneInfo不同时区的时间转换
1.枚举计算机上存在的时区
void write() {
ReadOnlyCollection<TimeZoneInfo> tzCollection;
tzCollection = TimeZoneInfo.GetSystemTimeZones();
foreach (TimeZoneInfo timeZone in tzCollection)
Console.WriteLine(" {0}: {1}", timeZone.Id, timeZone.DisplayName);
}
2.不同时区的时间转换
public static class Common
{
const string Source= "GMT Standard Time";
const string target= "China Standard Time";
public static DateTime GetTime(DateTime time) {
return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.SpecifyKind(time, DateTimeKind.Unspecified), SourceID, target);
}
}