Share via


タイム ゾーン一覧の作成

サブスクライバが有効なタイム ゾーンを選択できるように、サブスクリプション管理インターフェイスでタイム ゾーンの一覧を提供する必要がある場合は、TimeZone および TimeZoneEnumeration クラスを使用します。以下の例は、言語に対応するタイム ゾーンの一覧を表示する場合に、マネージ コードを使用する方法と、Microsoft Visual Basic Scripting Edition (VBScript) を使用する方法 (COM 相互運用の一例) を示しています。

マネージ コードの例

次のコード例では、マネージ コードで 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 相互運用の例

次のコード例では、アンマネージ コードで TimeZoneEnumeration オブジェクトを使用して、"en" ロケールに一致する 2 ~ 40 の識別子を持つタイム ゾーンのタイム ゾーン識別子を一覧表示します。

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

参照

概念

Subscription オブジェクトの作成
サブスクリプションの追加
サブスクリプションの更新
サブスクリプションの削除
サブスクリプション フィールド情報の取得
サブスクライバ ロケール一覧の作成

その他の技術情報

NS<SubscriptionClassName>View

ヘルプおよび情報

SQL Server 2005 の参考資料の入手