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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.