转换时间
var d = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, "Pacific Standard Time");
获取所有Id
StringBuilder sb = new StringBuilder();
foreach (var t in TimeZoneInfo.GetSystemTimeZones().OrderBy(d => d.Id))
{
sb.AppendLine(t.Id + " | " + t.StandardName + " | " + t.DisplayName + " | " + t.DaylightName);
}
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "tz.txt"), sb.ToString());
Console.WriteLine("Hello World!");
用TimeZoneNames这个可以转成英文的显示:
var v = TZNames.GetDisplayNameForTimeZone(t.Id, "en_US");
用TimeZoneConverter这个可以转成linux也识别的id:
var tz = TZConvert.WindowsToIana(IDStrings[i]);
在windows中,可以使用:
tzutil /l命令来获取时区列表