Click here to Skip to main content
13,902,146 members
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 12 Sep 2007
Licenced CPOL

Time Zone Class

, 20 Sep 2007
Rate this:
Please Sign up or sign in to vote.
The TimeZoneInfo class provides properties and methods for any time zone on the system.


This is yet another time zone class that gives you full access and functionality for different time zones. As we all know, .NET's (up to Framework 2) Time Zone class is not of much use since it only gives us objects that are associated with the current time zone. Therefore, I decided to create a time zone class called TimeZoneInfo that can give us information and methods for the other time zones.

The TimeZoneInfo class does pure .NET implementation and uses only one API method to set the current system computer's TimeZone. This means 99% managed code compared to some other time zone implementations.


I have seen many time zone classes, but almost all of them were lacking some features or the functions were implemented incorrectly. Time zone class may seem to be an easy task at first, but believe me, it is kind of tricky. The TimeZoneInfo class is based on the windows registry information under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Time Zones, so it is critical that the registry includes the latest updates from Microsoft.
The class provides all the information and the functionality for the time zones. For example, it provides Daylight Saving Time dates for the time zone, Current UtcOffset, Current Time, Current System Time Zone etc.

Used API Functions

SetTimeZoneInformation To set the current system time zone


DisplayName Gets the display name of the time zone
DaylightName Gets the daylight saving name of the time zone
StandardName Gets the standard name of the time zone
CurrentTime Gets the current date and time of the time zone
CurrentUtcOffset Gets the current UTC (Coordinated Universal Time) offset of the time zone
CurrentTimeZone Gets or sets the current time zone for this computer system
StandardUtcOffset Gets the standard UTC (Coordinated Universal Time) offset of the time zone
Id Gets the id of the time zone


NameDescription Parameter Return Value
GetTimeZones Gets an array of all time zones on the system NoneArray of TimeZoneInfo
FromStandardName Gets a TimeZoneInfo.Object from standard name Standard Name (string) TimeZoneInfo
FromId Gets a TimeZoneInfo.Object from Id Id (string)TimeZoneInfo
GetDaylightChanges Returns the daylight saving time for a particular year Year (Integer)DaylightTime
IsDaylightSavingTime Returns a value indicating whether this time zone is within a daylight saving time period NoneTrue/False (Boolean)
Refresh Refreshes the information of the time zone object NoneNone
SortSorts the elements in a list(Of TimeZoneInfo) object/TimeZoneInfo array based on standard UTC offset or display name tzInfos (List(Of TimeZoneInfo)/TimeZoneInfo array None
ToString Returns a System.String that represents the current TimeZoneInfo object noneDisplay Name (String)
Equals Determines whether the specified System.Object is equal to the current System.Objectobj (Object)True/False (Boolean)

Using The Code

For more examples, check the demo project.

'Get all the time zones on the system and show them in a ListBox control
Me.ListBox1.DataSource = TimeZoneInfo.GetTimeZones

Dim tzInfo As TimeZoneInfo 
'Create new instance of a TimeZoneInfo for a specific time zone 
tzInfo = New TimeZoneInfo("Pacific Standard Time") 
'Or tzInfo = TimeZoneInfo.FromStandardName("Pacific Standard Time") 
'Get the current UtcOffset of the time zone 
Dim utcOffset As TimeSpan = tzInfo.CurrentUtcOffset 
'Get the current time of the time zone 
Dim time As DateTime = tzInfo.CurrentTime 
'Get a value specifying if it is a daylight saving time 
'currently for the time zone 
Dim isDaylight As Boolean = tzInfo.IsDaylightSavingTime 
'Get daylight changes for the year 2007 of the time zone 
Dim dStart, dEnd As DateTime 
Dim dt As System.Globalization.DaylightTime 
dt = tzInfo.GetDaylightChanges(2007) 
dStart = dt.Start 
dEnd = dt.End 
'And much more 

System Requirements

  • Windows NT/2000/XP (tested only on XP)
  • Framework 2.0

TimeZoneInfo Information


  • 12 September, 2007 -- Original version posted
  • 17 September, 2007 -- (Some internal minor changes to optimize the Sort functionality)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Arman Ghazanchyan
Software Developer (Senior) ZipEdTech
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionIt's C# version Pin
aree21427-Nov-14 18:47
memberaree21427-Nov-14 18:47 
QuestionThe system don't Allow me to change time Zone Pin
jason55724-Aug-12 7:01
memberjason55724-Aug-12 7:01 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey23-Feb-12 21:53
professionalManoj Kumar Choubey23-Feb-12 21:53 
GeneralConverting TimeZone Values Pin
cheecio17-Feb-10 1:12
membercheecio17-Feb-10 1:12 
GeneralWindows Vista and Windows 7 Pin
Nonasm9-Feb-10 21:23
memberNonasm9-Feb-10 21:23 
GeneralNot running in ASP.NET Pin
Xavito11-Jun-09 9:50
memberXavito11-Jun-09 9:50 
GeneralRe: Not running in ASP.NET Pin
Arman Ghazanchyan11-Jun-09 10:24
memberArman Ghazanchyan11-Jun-09 10:24 
GeneralRe: Not running in ASP.NET Pin
Xavito11-Jun-09 16:03
memberXavito11-Jun-09 16:03 
GeneralRe: Not running in ASP.NET Pin
Xavito11-Jun-09 16:12
memberXavito11-Jun-09 16:12 
GeneralRe: Not running in ASP.NET Pin
Arman Ghazanchyan9-Aug-09 19:32
memberArman Ghazanchyan9-Aug-09 19:32 
GeneralRe: Not running in ASP.NET [modified] Pin
Fundacion8-May-10 9:46
memberFundacion8-May-10 9:46 
GeneralOS Localization Compatibility Pin
simster7723-Jan-09 10:01
membersimster7723-Jan-09 10:01 
GeneralRe: OS Localization Compatibility Pin
Arman Ghazanchyan23-Jan-09 10:43
memberArman Ghazanchyan23-Jan-09 10:43 
GeneralRe: OS Localization Compatibility Pin
simster7723-Jan-09 10:47
membersimster7723-Jan-09 10:47 
GeneralRe: OS Localization Compatibility Pin
EngBol3-Nov-11 6:25
memberEngBol3-Nov-11 6:25 
GeneralNew approach in .Net 3.5 Pin
neilio2-Dec-08 8:59
memberneilio2-Dec-08 8:59 
GeneralRe: New approach in .Net 3.5 Pin
Arman Ghazanchyan3-Dec-08 11:56
memberArman Ghazanchyan3-Dec-08 11:56 
GeneralHelp Required Pin
Krishnraj16-Sep-08 1:11
memberKrishnraj16-Sep-08 1:11 
samiji15-Sep-08 20:04
membersamiji15-Sep-08 20:04 
GeneralRe: HELP PLEASE [modified] Pin
Arman Ghazanchyan15-Sep-08 20:24
memberArman Ghazanchyan15-Sep-08 20:24 
GeneralGood, but don't depend on the registry Pin
neilio25-Sep-07 17:02
memberneilio25-Sep-07 17:02 
GeneralRe: Good, but don't depend on the registry [modified] Pin
Arman Ghazanchyan25-Sep-07 18:30
memberArman Ghazanchyan25-Sep-07 18:30 
GeneralRe: Good, but don't depend on the registry Pin
iwonder26-Sep-07 5:22
memberiwonder26-Sep-07 5:22 
GeneralRe: Good, but don't depend on the registry Pin
Arman Ghazanchyan26-Sep-07 8:27
memberArman Ghazanchyan26-Sep-07 8:27 
GeneralRe: Good, but don't depend on the registry Pin
iwonder27-Sep-07 6:48
memberiwonder27-Sep-07 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 21 Sep 2007
Article Copyright 2007 by Arman Ghazanchyan
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid