填充时区列表

如果您需要在订阅管理界面中提供一个时区列表以使订阅方可以选择有效的时区,则请使用 TimeZone 类和 TimeZoneEnumeration 类。下面的示例显示如何使用托管代码和 Microsoft Visual Basic 脚本版本 (VBScript) 列出语言的时区以阐释 COM interop。

托管代码示例

以下代码示例显示如何在托管代码中使用 TimeZoneEnumeration 对象来列出客户端计算机当前区域性设置的时区名称:

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 示例

以下代码示例显示如何在非托管代码中使用 TimeZoneEnumeration 对象来列出其标识符介于 2 和 40 之间,并符合“en”区域设置的时区的时区标识符:

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

请参阅

概念

创建订阅对象
添加订阅
更新订阅
删除订阅
获取订阅字段信息
填充订阅服务器区域设置列表

其他资源

NS<SubscriptionClassName>View

帮助和信息

获取 SQL Server 2005 帮助