foreach (var zone in TimeZoneInfo.GetSystemTimeZones()) {
Console.WriteLine("{0:00.00} {1}", zone.BaseUtcOffset.TotalHours, zone.Id);
}
列表中间是您可能感兴趣的时区:
...
-01,00 Azores Standard Time
-01,00 Cape Verde Standard Time
00,00 Morocco Standard Time
00,00 UTC
00,00 GMT Standard Time
00,00 Greenwich Standard Time
01,00 W. Europe Standard Time
01,00 Central Europe Standard Time
01,00 Romance Standard Time
01,00 Central European Standard Time
01,00 W. Central Africa Standard Time
01,00 Namibia Standard Time
...
Dim IST As TimeZoneInfo
' Declare necessary TimeZoneInfo.AdjustmentRule objects for time zone
' delta is the amount of change during DST
Dim delta As New TimeSpan(1, 0, 0)
Dim adjustment As TimeZoneInfo.AdjustmentRule
Dim adjustmentList As New List(Of TimeZoneInfo.AdjustmentRule)
' Declare transition time variables to hold transition time information
Dim transitionRuleStart, transitionRuleEnd As TimeZoneInfo.TransitionTime
' Simplifying some elements for later use
Dim CurrTime As Date = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified)
Dim EST As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
Dim CST As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")
Dim UTC As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("UTC")
' Define new Irish Standard Time zone at UTC, but with DST
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00 AM#, 3, 2, DayOfWeek.Sunday)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00 AM#, 11, 1, DayOfWeek.Sunday)
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#1/1/2007#, Date.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment)
Dim adjustments(adjustmentList.Count - 1) As TimeZoneInfo.AdjustmentRule
adjustmentList.CopyTo(adjustments)
IST = TimeZoneInfo.CreateCustomTimeZone("IST", New TimeSpan(0, 0, 0), _
"(GMT 00:00) Irish Standard Time (Ireland)", "Irish Standard Time", _
"Irish Daylight Time", adjustments)
' Testing.
Debug.Print("Time in Ireland: " & TimeZoneInfo.ConvertTime(CurrTime, UTC, IST))
Debug.Print("Time in New York: " & TimeZoneInfo.ConvertTime(CurrTime, UTC, EST))
Debug.Print("Time in Chicago: " & TimeZoneInfo.ConvertTime(CurrTime, UTC, CST))
1
爱尔兰的时区ID为"GMT Standard Time" . 这个适合我使用 TimeZoneInfo.FindSystemTimeZoneById 一个Windows 7 .
ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("The local system has the following {0} time zones", zones.Count);
foreach (TimeZoneInfo zone in zones)
Console.WriteLine(zone.Id);
7 回答
来自MSDN:
在我的本地电脑(Windows 7)我没有找到ID“爱尔兰标准时间”
MSDN TimeZoneInfo
似乎没有任何这样的时区 .
您可以使用
GetSystemTimeZones
方法获取时区 . 我用过这段代码:列表中间是您可能感兴趣的时区:
我想你得到 TimeZoneNotFoundException
Link to msdn
使用的注册表项是:
TimeZoneInfo
支持的时区列表位于HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
中 . 我的Windows 7副本没有爱尔兰的任何信息 .我试图在VB.NET中找到这个解决方案 . 感谢https://msdn.microsoft.com/en-us/library/bb397784(v=vs.110).aspx的代码,我找到了解决方案 . 希望这会让你到达需要一个好的VB.NET到C#转换器来结束这个已有5年历史的问题 .
爱尔兰的时区ID为"GMT Standard Time" . 这个适合我使用
TimeZoneInfo.FindSystemTimeZoneById
一个Windows 7 .从msdn复制的示例
运行它以查看您可以使用的时区ID: