予定の期間内に、ユーザーが予定の開始時とは異なるタイム ゾーンに移動する場合があります。 この例では、太平洋タイム ゾーン (UTC-8) で開始して東部タイム ゾーン (UTC-5) で終了する予定を作成します。
例
このコード サンプルでは、Microsoft Windows で認識されるすべてのタイム ゾーンを表す TimeZones オブジェクトを使用します。 また、TimeZone オブジェクトを使用して、AppointmentItem オブジェクトの StartTimeZone プロパティと EndTimeZone プロパティを設定または取得します。
Outlook では、すべての日付がローカル時刻で表示されます。これはユーザーの現在のタイム ゾーンで表され、Windows コントロール パネルのユーザーの設定によって制御されます。 また、Outlook では、 スタート や 終了などのプロパティをローカル時刻で設定または取得します。 ただし、Outlook では、日付と時刻の値は、現地時刻ではなく協定世界時 (UTC) として格納されます。 PropertyAccessor オブジェクトを使用して Appointment.Start の内部値を調べると、内部の日付と時刻の値が、同等の UTC 日付と時刻の値に変換されたローカルの日付と時刻の値と等しくなります。
Outlook は、タイム ゾーンの情報を使用して、予定を保存するときは予定を正しい UTC 時刻にマップし、予定表にアイテムを表示するときは正しい現地時刻に戻します。 StartTimeZone の変更は、TimeZones によって返されるオブジェクトの CurrentTimeZone プロパティによって表される、常にローカル タイム ゾーンで表される Appointment.Start の値に影響します。 同様に、EndTimeZone を変更すると、Application.TimeZones によって返されるオブジェクトの CurrentTimeZone プロパティで表される、常に現地のタイム ゾーンで表現される Appointment.End の値に影響があります。
TimeZones オブジェクトから特定の TimeZone を取得するには、Windows レジストリに含まれる TimeZone に対する現地に依存しないキーを使用します。 ロケールに依存しない TimeZone キーは、次のキーの下に一覧表示されます。 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TimeZones
Visual Studio を使用してこのコード例をテストする場合、Microsoft.Office.Interop.Outlook 名前空間をインポートするときに、まず Microsoft Outlook 15.0 オブジェクト ライブラリ コンポーネントへの参照を追加し、Outlook 変数を指定します。 Imports または using ステートメントは、コード例の関数の前に直接置くことはできません。パブリック Class 宣言の前に追加する必要があります。 次のコード行は、Visual Basic および C# でインポートおよび割り当てを行う方法を示しています。
Imports Outlook = Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
Private Sub TimeZoneExample()
Dim appt As Outlook.AppointmentItem = _
CType(Application.CreateItem( _
Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem)
Dim tzs As Outlook.TimeZones = Application.TimeZones
' Obtain timezone using indexer and locale-independent key
Dim tzEastern As Outlook.TimeZone = tzs("Eastern Standard Time")
Dim tzPacific As Outlook.TimeZone = tzs("Pacific Standard Time")
appt.Subject = "SEA - JFK Flight"
appt.Start = DateTime.Parse("8/9/2006 8:00 AM")
appt.StartTimeZone = tzPacific
appt.End = DateTime.Parse("8/9/2006 5:30 PM")
appt.EndTimeZone = tzEastern
appt.Display(False)
End Sub
private void TimeZoneExample()
{
Outlook.AppointmentItem appt = Application.CreateItem(
Outlook.OlItemType.olAppointmentItem)
as Outlook.AppointmentItem;
Outlook.TimeZones tzs = Application.TimeZones;
// Obtain timezone using indexer and locale-independent key
Outlook.TimeZone tzEastern = tzs["Eastern Standard Time"];
Outlook.TimeZone tzPacific = tzs["Pacific Standard Time"];
appt.Subject = "SEA - JFK Flight";
appt.Start = DateTime.Parse("8/9/2006 8:00 AM");
appt.StartTimeZone = tzPacific;
appt.End = DateTime.Parse("8/9/2006 5:30 PM");
appt.EndTimeZone = tzEastern;
appt.Display(false);
}