我试图在 VB.NET 中找到这个解决方案。感谢https://msdn.microsoft.com/en-us/library/bb397784(v=vs.110).aspx 的代码,我找到了解决方案。希望这将使您达到只需要一个好的 VB.NET 到 C# 转换器来结束这个 5 年前的问题的地步。
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))