TimeZoneInfo.GetAmbiguousTimeOffsets メソッド

定義

あいまいな日付と時刻を割り当て可能な、日付と時刻に関する情報を返します。

オーバーロード

GetAmbiguousTimeOffsets(DateTime)

あいまいな日付と時刻を割り当て可能な、日付と時刻に関する情報を返します。

GetAmbiguousTimeOffsets(DateTimeOffset)

あいまいな日付と時刻を割り当て可能な、日付と時刻に関する情報を返します。

GetAmbiguousTimeOffsets(DateTime)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

あいまいな日付と時刻を割り当て可能な、日付と時刻に関する情報を返します。

public:
 cli::array <TimeSpan> ^ GetAmbiguousTimeOffsets(DateTime dateTime);
public TimeSpan[] GetAmbiguousTimeOffsets (DateTime dateTime);
member this.GetAmbiguousTimeOffsets : DateTime -> TimeSpan[]
Public Function GetAmbiguousTimeOffsets (dateTime As DateTime) As TimeSpan()

パラメーター

dateTime
DateTime

日付と時刻。

戻り値

特定の日付と時刻を割り当て可能な、世界協定時刻 (UTC) オフセットを表すオブジェクトの配列。

例外

dateTime はあいまいな時刻ではありません。

次の例では、 メソッドを使用GetAmbiguousTimeOffsets(DateTime)してあいまいな時刻を対応する協定世界時 (UTC) 時刻にマップする という名前ShowPossibleUtcTimesのメソッドを定義します。

private void ShowPossibleUtcTimes(DateTime ambiguousTime, TimeZoneInfo timeZone)
{
   // Determine if time is ambiguous in target time zone
   if (! timeZone.IsAmbiguousTime(ambiguousTime))
   {
      Console.WriteLine("{0} is not ambiguous in time zone {1}.", 
                        ambiguousTime, 
                        timeZone.DisplayName);
   }
   else
   {
      // Display time and its time zone (local, UTC, or indicated by timeZone argument)
      string originalTimeZoneName; 
      if (ambiguousTime.Kind == DateTimeKind.Utc)
         originalTimeZoneName = "UTC";
      else if (ambiguousTime.Kind == DateTimeKind.Local)
         originalTimeZoneName = "local time";
      else
         originalTimeZoneName = timeZone.DisplayName;

      Console.WriteLine("{0} {1} maps to the following possible times:", 
                        ambiguousTime, originalTimeZoneName);
      // Get ambiguous offsets 
      TimeSpan[] offsets = timeZone.GetAmbiguousTimeOffsets(ambiguousTime);
      // Handle times not in time zone of timeZone argument
      // Local time where timeZone is not local zone
      if ((ambiguousTime.Kind == DateTimeKind.Local) && ! timeZone.Equals(TimeZoneInfo.Local)) 
         ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Local, timeZone);
      // UTC time where timeZone is not UTC zone   
      else if ((ambiguousTime.Kind == DateTimeKind.Utc) && ! timeZone.Equals(TimeZoneInfo.Utc))
         ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Utc, timeZone);

      // Display each offset and its mapping to UTC
      foreach (TimeSpan offset in offsets)
      {
         if (offset.Equals(timeZone.BaseUtcOffset))
            Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.StandardName, ambiguousTime - offset);
         else
            Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.DaylightName, ambiguousTime - offset);
      }
   }            
}
let showPossibleUtcTimes (ambiguousTime: DateTime) (timeZone: TimeZoneInfo) =
    // Determine if time is ambiguous in target time zone
    if not (timeZone.IsAmbiguousTime ambiguousTime) then
        printfn $"{ambiguousTime} is not ambiguous in time zone {timeZone.DisplayName}."
    else
        // Display time and its time zone (local, UTC, or indicated by timeZone argument)
        let originalTimeZoneName =
            match ambiguousTime.Kind with
            | DateTimeKind.Utc -> "UTC"
            | DateTimeKind.Local -> "local time"
            | _ -> timeZone.DisplayName

        printfn $"{ambiguousTime} {originalTimeZoneName} maps to the following possible times:"
        // Get ambiguous offsets 
        let offsets = timeZone.GetAmbiguousTimeOffsets ambiguousTime
        // Handle times not in time zone of timeZone argument
        // Local time where timeZone is not local zone
        let ambiguousTime =
            if (ambiguousTime.Kind = DateTimeKind.Local) && not (timeZone.Equals TimeZoneInfo.Local) then 
                TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Local, timeZone)
            // UTC time where timeZone is not UTC zone   
            elif (ambiguousTime.Kind = DateTimeKind.Utc) && not (timeZone.Equals TimeZoneInfo.Utc) then
                TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Utc, timeZone)
            else 
                ambiguousTime
        // Display each offset and its mapping to UTC
        for offset in offsets do
            if offset.Equals timeZone.BaseUtcOffset then
                printfn $"If {ambiguousTime} is {timeZone.StandardName}, {ambiguousTime - offset} UTC"
            else
                printfn $"If {ambiguousTime} is {timeZone.DaylightName}, {ambiguousTime - offset} UTC"
Private Sub ShowPossibleUtcTimes(ambiguousTime As Date, timeZone As TimeZoneInfo)
   ' Determine if time is ambiguous in target time zone
   If Not timeZone.IsAmbiguousTime(ambiguousTime) Then
      Console.WriteLine("{0} is not ambiguous in time zone {1}.", _
                        ambiguousTime, _
                        timeZone.DisplayName)
   Else
      ' Display time and its time zone (local, UTC, or indicated by timeZone argument)
      Dim originalTimeZoneName As String 
      If ambiguousTime.Kind = DateTimeKind.Utc Then
         originalTimeZoneName = "UTC"
      ElseIf ambiguousTime.Kind = DateTimeKind.Local Then
         originalTimeZoneName = "local time"
      Else
         originalTimeZoneName = timeZone.DisplayName
      End If      
      Console.WriteLine("{0} {1} maps to the following possible times:", _
                        ambiguousTime, originalTimeZoneName)
      ' Get ambiguous offsets 
      Dim offsets() As TimeSpan = timeZone.GetAmbiguousTimeOffsets(ambiguousTime)
      ' Handle times not in time zone of timeZone argument
      ' Local time where timeZone is not local zone
      If (ambiguousTime.Kind = DateTimeKind.Local) And Not timeZone.Equals(TimeZoneInfo.Local) Then
         ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Local, timeZone)
      ' UTC time where timeZone is not UTC zone   
      ElseIf (ambiguousTime.Kind = DateTimeKind.Utc) And Not timeZone.Equals(TimeZoneInfo.Utc) Then
         ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Utc, timeZone)
      End If       
      ' Display each offset and its mapping to UTC
      For Each offset As TimeSpan In offsets
         If offset.Equals(timeZone.BaseUtcOffset) Then
            Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.StandardName, ambiguousTime - offset)
         Else
            Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.DaylightName, ambiguousTime - offset)
         End If   
      Next
   End If            
End Sub

メソッドは、次のようなコードを使用して呼び出すことができます。

Console.WriteLine();
ShowPossibleUtcTimes(new DateTime(2007, 11, 4, 1, 0, 0), 
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
Console.WriteLine();
ShowPossibleUtcTimes(new DateTime(2007, 11, 4, 01, 00, 00, DateTimeKind.Local), 
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
Console.WriteLine();
ShowPossibleUtcTimes(new DateTime(2007, 11, 4, 00, 00, 00, DateTimeKind.Local), 
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
Console.WriteLine();                     
ShowPossibleUtcTimes(new DateTime(2007, 11, 4, 01, 00, 00, DateTimeKind.Unspecified), 
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
Console.WriteLine();
ShowPossibleUtcTimes(new DateTime(2007, 11, 4, 07, 00, 00, DateTimeKind.Utc), 
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
// 
// This example produces the following output if run in the Pacific time zone:
//
//    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//       
//    11/4/2007 1:00:00 AM Pacific Standard Time is not ambiguous in time zone (GMT-06:00) Central Time (US & Canada).
//     
//    11/4/2007 12:00:00 AM local time maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//    
//    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//       
//    11/4/2007 7:00:00 AM UTC maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//
printfn ""
showPossibleUtcTimes(DateTime(2007, 11, 4, 1, 0, 0)) (TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time")
printfn ""
showPossibleUtcTimes (DateTime(2007, 11, 4, 01, 00, 00, DateTimeKind.Local)) (TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time")
printfn ""
showPossibleUtcTimes (DateTime(2007, 11, 4, 00, 00, 00, DateTimeKind.Local)) (TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time")
printfn ""                     
showPossibleUtcTimes (DateTime(2007, 11, 4, 01, 00, 00, DateTimeKind.Unspecified)) (TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time")
printfn ""
showPossibleUtcTimes (DateTime(2007, 11, 4, 07, 00, 00, DateTimeKind.Utc)) (TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time")

// This example produces the following output if run in the Pacific time zone:
//
//    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//       
//    11/4/2007 1:00:00 AM Pacific Standard Time is not ambiguous in time zone (GMT-06:00) Central Time (US & Canada).
//     
//    11/4/2007 12:00:00 AM local time maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//    
//    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//       
//    11/4/2007 7:00:00 AM UTC maps to the following possible times:
//    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
//    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
//
ShowPossibleUtcTimes(#11/4/2007 1:00:00#, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 01, 00, 00, DateTimeKind.Local), _
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 00, 00, 00, DateTimeKind.Local), _
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()                     
ShowPossibleUtcTimes(New Date(2007, 11, 4, 01, 00, 00, DateTimeKind.Unspecified), _
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 07, 00, 00, DateTimeKind.Utc), _
                     TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
' 
' This example produces the following output if run in the Pacific time zone:
'
'    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
'    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
'    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
' 
'    11/4/2007 1:00:00 AM Pacific Standard Time is not ambiguous in time zone (GMT-06:00) Central Time (US & Canada).
' 
'    11/4/2007 12:00:00 AM local time maps to the following possible times:
'    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
'    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
' 
'    11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
'    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
'    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
' 
'    11/4/2007 7:00:00 AM UTC maps to the following possible times:
'    If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
'    If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC

注釈

次の表に示すように、このメソッドの正確な動作は、 プロパティと オブジェクトのTimeZoneInfo関係Kindによって異なります。

TimeZoneInfo オブジェクトの種類 Kind プロパティの値 動作
TimeZoneInfo.Local DateTimeKind.Local または DateTimeKind.Unspecified のあいまいな時間オフセットを dateTime返します。
TimeZoneInfo.Local DateTimeKind.Utc ローカル時刻に変換 dateTime し、その時刻のあいまいな時刻オフセットを返します。
TimeZoneInfo.Utc 任意の値。 をスローします ArgumentException
その他のタイム ゾーン。 Local または DateTimeKind.Utc 指定したタイム ゾーンに変換 dateTime し、その時刻があいまいかどうかを判断します。
その他のタイム ゾーン。 DateTimeKind.Unspecified 指定したタイム ゾーンで があいまいかどうかを dateTime 判断します。

このメソッドによって返される配列内のオブジェクトの TimeSpan 順序は未定義です。 ただし、タイム ゾーンの標準時刻からのオフセットを表す要素は、その値とタイム ゾーンの BaseUtcOffset プロパティを比較することで判断できます。 あいまいな時刻をタイム ゾーンの標準時にマップするには、「 方法: あいまいな時刻を解決する」を参照してください。

こちらもご覧ください

適用対象

GetAmbiguousTimeOffsets(DateTimeOffset)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

あいまいな日付と時刻を割り当て可能な、日付と時刻に関する情報を返します。

public:
 cli::array <TimeSpan> ^ GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset);
public TimeSpan[] GetAmbiguousTimeOffsets (DateTimeOffset dateTimeOffset);
member this.GetAmbiguousTimeOffsets : DateTimeOffset -> TimeSpan[]
Public Function GetAmbiguousTimeOffsets (dateTimeOffset As DateTimeOffset) As TimeSpan()

パラメーター

dateTimeOffset
DateTimeOffset

日付と時刻。

戻り値

特定の日付と時刻を割り当て可能な、世界協定時刻 (UTC) オフセットを表すオブジェクトの配列。

例外

dateTimeOffset はあいまいな時刻ではありません。

注釈

このメソッドの正確な動作は、 パラメーターの プロパティと TimeZoneInfo オブジェクトのdateTimeOffset関係Offsetによって異なります。 プロパティの値が Offset 、その日付と時刻の世界協定時刻 (UTC) からの現在のタイム ゾーンの可能なオフセットに対応する場合、メソッドは可能なオフセットを返します。 それ以外の場合は、現在のタイム ゾーンの時刻に変換 dateTimeOffset し、その日付と時刻の可能なオフセットを返します。

このメソッドによって返される配列内のオブジェクトの TimeSpan 順序は未定義です。 ただし、タイム ゾーンの標準時刻からのオフセットを表す要素は、その値とタイム ゾーンの BaseUtcOffset プロパティを比較することで判断できます。 あいまいな時刻をタイム ゾーンの標準時にマップするには、「 方法: あいまいな時刻を解決する」を参照してください。

こちらもご覧ください

適用対象