Answers
// 查看当前系统支持的所有时区,主要是用 StandardName,
// 不过 ToString() 会显示时间差以及城市,可以帮忙人工判断
// foreach (var z in TimeZoneInfo.GetSystemTimeZones()) {
// Console.WriteLine($"{z.StandardName} - ${z}");
// }
// 获取英国的时区
TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
Console.WriteLine(zone);
Console.WriteLine(DateTime.Now.Kind); // Local
var gtmTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, zone);
Console.WriteLine(gtmTime);
var d = new DateTime(2015, 9, 1, 18, 0, 0, DateTimeKind.Utc);
Console.WriteLine(d.Kind); // Utc
Console.WriteLine(TimeZoneInfo.ConvertTime(d, TimeZoneInfo.Utc, zone));
forjune
answered 9 years, 2 months ago