Converts a time to the time in a particular time zone.
Module Example
Public Sub Main()
Dim time1 As Date = #1/1/2010 12:01AM#
Dim time2 As Date = #11/6/2010 11:30PM#
Dim times() As DateTimeOffset = { New DateTimeOffset(time1, TimeZoneInfo.Local.GetUtcOffset(time1)), _
New DateTimeOffset(time1, Timespan.Zero), _
New DateTimeOffset(time2, TimeZoneInfo.Local.GetUtcOffset(time2)), _
New DateTimeOffset(time2.AddHours(3), TimeZoneInfo.Local.GetUtcOffset(time2.AddHours(3))) }
Dim est As TimeZoneInfo
est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
Console.WriteLine("Local time zone: {0}", TimeZoneInfo.Local.DisplayName)
For Each timeToConvert As DateTimeOffset In times
Dim targetTime As DateTimeOffset = TimeZoneInfo.ConvertTime(timeToConvert, est)
Console.WriteLine("Converted {0} to {1}.", timeToConvert, targetTime)
Next
End Sub
End Module
Related examples in the same category