擴展時區清單
如果您需要在訂閱管理介面中提供時區清單,以便讓訂閱者可以選取有效的時區,請使用 TimeZone 和 TimeZoneEnumeration 類別。下列範例顯示,如何利用 Managed 程式碼和 Microsoft Visual Basic Scripting Edition (VBScript) 列出語言時區來說明 COM Interop。
Managed 程式碼範例
下列程式碼範例顯示如何利用 Managed 程式碼中的 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 範例
下列程式碼範例顯示如何利用 Unmanaged 程式碼中的 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
請參閱
概念
建立訂閱物件
新增訂閱
更新訂閱
刪除訂閱
取得訂閱欄位資訊
擴展訂閱者地區設定程式碼