Populating a Time Zone List

If you need to provide a list of time zones in your subscription management interface so that subscribers can select valid time zones, use the TimeZone and TimeZoneEnumeration classes. The examples below show how to list the time zones for a language using managed code and using Microsoft Visual Basic Scripting Edition (VBScript) to illustrate COM interop.

The following code example shows how to use a TimeZoneEnumeration object in managed code to list time zone names for the client computer's current culture setting:

string instanceName = "Tutorial";

// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);

// Create the TimeZoneEnumeration.
TimeZoneEnumeration testTimeZoneEnumeration =
    new TimeZoneEnumeration(testInstance,

// Step through the enumeration, populating
// the drop-down list as you go. Note that the TimeZone
// reference must include the namespace, because there is
// an identically named class in the System namespace.
thisTimeZone in testTimeZoneEnumeration)

The following code example shows how to use a TimeZoneEnumeration object in unmanaged code to list time zone identifiers for the time zones with an identifier between 2 and 40 that match the "en" locale:

Dim testInstance, testTimeZoneEnumeration, timeZones
const instanceName = "Tutorial"

' Create the NSInstance object.
set testInstance = WScript.CreateObject( _ 
testInstance.Initialize instanceName

' Create the TimeZoneEnumeration object.
set testTimeZoneEnumeration = WScript.CreateObject( _ 
testTimeZoneEnumeration.Initialize (testInstance), "en" 

' Print the valid time zone IDs between 2 and 40
for each thisTimeZone in testTimeZoneEnumeration
    if thisTimeZone.TimeZoneId >=2 _
        and thisTimeZone.TimeZoneId <=40 then
        timeZones = timeZones & thisTimeZone.TimeZoneId & ", "
    end if
WScript.echo timeZones

Community Additions