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.

Managed Code Example

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,
    System.Globalization.CultureInfo.CurrentUICulture.Parent.Name);

// 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.
foreach(Microsoft.SqlServer.NotificationServices.TimeZone
thisTimeZone in testTimeZoneEnumeration)
{
    Console.WriteLine(thisTimeZone.TimeZoneName);
}

COM Interop Example

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( _ 
    "Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName

' Create the TimeZoneEnumeration object.
set testTimeZoneEnumeration = WScript.CreateObject( _ 
    "Microsoft.SqlServer.NotificationServices.timeZoneEnumeration")
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
next
WScript.echo timeZones

See Also

Concepts

Creating a Subscription Object
Adding a Subscription
Updating a Subscription
Deleting a Subscription
Getting Subscription Field Information
Populating a Subscriber Locale List

Other Resources

NS<SubscriptionClassName>View

Help and Information

Getting SQL Server 2005 Assistance