2.9. Convert Dates and Times Across Time Zones

Problem

You need to work with dates and times in different time zones and be able to convert between them.

Solution

Use one of the conversion methods (ConvertTime, ConvertTimeBySystemTimeZoneId, ConvertTimeFromUtc, or ConvertTimeToUtc) of the new TimeZoneInfo class.

How It Works

Previous versions of .NET included the TimeZone class, which was used to represent a world time zone for a given date and time. Although this was useful, the class was severely limited because it was able to represent only the local time zone. Furthermore, conversions were limited to the local time zone and UTC.

The .NET Framework 3.5 introduces the NotInheritable TimeZoneInfo class, which adds important functionality that ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.