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 모든 값 ArgumentExceptionthrow합니다.
다른 표준 시간대. 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 은 모호한 시간이 아닙니다.

설명

이 메서드의 정확한 동작은 매개 변수의 dateTimeOffset 속성과 TimeZoneInfo 개체 간의 Offset 관계에 따라 달라집니다. 속성 값이 Offset 해당 날짜 및 시간에 대한 UTC(협정 세계시)의 현재 표준 시간대의 가능한 오프셋에 해당하는 경우 메서드는 가능한 오프셋을 반환합니다. 그렇지 않으면 현재 표준 시간대의 시간으로 변환 dateTimeOffset 한 다음 해당 날짜 및 시간의 가능한 오프셋을 반환합니다.

이 메서드에서 반환된 배열의 TimeSpan 개체 순서는 정의되지 않습니다. 그러나 해당 값을 표준 시간대의 속성과 BaseUtcOffset 비교하여 표준 시간대 표준시에서 오프셋을 나타내는 요소를 확인할 수 있습니다. 모호한 시간을 표준 시간대의 표준 시간에 매핑하려면 방법: 모호한 시간 해결을 참조하세요.

추가 정보

적용 대상