TimeZoneInfo.GetAdjustmentRules 메서드

정의

현재 TimeZoneInfo.AdjustmentRule 개체에 적용되는 TimeZoneInfo 개체의 배열을 검색합니다.

public:
 cli::array <TimeZoneInfo::AdjustmentRule ^> ^ GetAdjustmentRules();
public TimeZoneInfo.AdjustmentRule[] GetAdjustmentRules ();
member this.GetAdjustmentRules : unit -> TimeZoneInfo.AdjustmentRule[]
Public Function GetAdjustmentRules () As TimeZoneInfo.AdjustmentRule()

반환

AdjustmentRule[]

이 표준 시간대에 대한 개체의 배열입니다.

예외

시스템에 조정 규칙의 메모리 내 사본을 만드는 데 사용할 메모리가 부족한 경우

예제

다음 예제에서는 로컬 시스템에 정의된 모든 표준 시간대를 검색하고 조정 규칙에 대한 전체 정보를 콘솔에 표시합니다.

private enum WeekOfMonth 
{
   First = 1,
   Second = 2,
   Third = 3,
   Fourth = 4,
   Last = 5,
}

private static void ShowStartAndEndDates()
{
   // Get all time zones from system
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   string[] monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
   // Get each time zone
   foreach (TimeZoneInfo timeZone in timeZones)
   {
      TimeZoneInfo.AdjustmentRule[] adjustments = timeZone.GetAdjustmentRules();
      // Display message for time zones with no adjustments
      if (adjustments.Length == 0)
      {
         Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName);
      }   
      else
      {
         // Handle time zones with 1 or 2+ adjustments differently
         bool showCount = false;
         int ctr = 0;
         string spacer = "";
         
         Console.WriteLine("{0} Adjustment rules", timeZone.StandardName);
         if (adjustments.Length > 1)
         {
            showCount = true;
            spacer = "   ";
         }   
         // Iterate adjustment rules
         foreach (TimeZoneInfo.AdjustmentRule adjustment in adjustments)
         {
            if (showCount)
            { 
               Console.WriteLine("   Adjustment rule #{0}", ctr+1);
               ctr++;
            }
            // Display general adjustment information
            Console.WriteLine("{0}   Start Date: {1:D}", spacer, adjustment.DateStart);
            Console.WriteLine("{0}   End Date: {1:D}", spacer, adjustment.DateEnd);
            Console.WriteLine("{0}   Time Change: {1}:{2:00} hours", spacer, 
                              adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes);
            // Get transition start information
            TimeZoneInfo.TransitionTime transitionStart = adjustment.DaylightTransitionStart;
            Console.Write("{0}   Annual Start: ", spacer);
            if (transitionStart.IsFixedDateRule)
            {
               Console.WriteLine("On {0} {1} at {2:t}", 
                                 monthNames[transitionStart.Month - 1], 
                                 transitionStart.Day, 
                                 transitionStart.TimeOfDay);
            }
            else
            {
               Console.WriteLine("The {0} {1} of {2} at {3:t}", 
                                 ((WeekOfMonth)transitionStart.Week).ToString(), 
                                 transitionStart.DayOfWeek.ToString(), 
                                 monthNames[transitionStart.Month - 1], 
                                 transitionStart.TimeOfDay);
            }
            // Get transition end information
            TimeZoneInfo.TransitionTime transitionEnd = adjustment.DaylightTransitionEnd;
            Console.Write("{0}   Annual End: ", spacer);
            if (transitionEnd.IsFixedDateRule)
            {
               Console.WriteLine("On {0} {1} at {2:t}", 
                                 monthNames[transitionEnd.Month - 1], 
                                 transitionEnd.Day, 
                                 transitionEnd.TimeOfDay);
            }
            else
            {
               Console.WriteLine("The {0} {1} of {2} at {3:t}", 
                                 ((WeekOfMonth)transitionEnd.Week).ToString(), 
                                 transitionEnd.DayOfWeek.ToString(), 
                                 monthNames[transitionEnd.Month - 1], 
                                 transitionEnd.TimeOfDay);
            }
         }
      }   
      Console.WriteLine();
   } 
}
type WeekOfMonth = 
    | First = 1
    | Second = 2
    | Third = 3
    | Fourth = 4
    | Last = 5

let showStartAndEndDates () =
    // Get all time zones from system
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    let monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
    // Get each time zone
    for timeZone in timeZones do
        let adjustments = timeZone.GetAdjustmentRules()
        // Display message for time zones with no adjustments
        if adjustments.Length = 0 then
            printfn $"{timeZone.StandardName} has no adjustment rules"
        else
            // Handle time zones with 1 or 2+ adjustments differently
            let mutable ctr = 0
            let showCount, spacer = 
                if adjustments.Length > 1 then
                    true, "   "
                else 
                    false, ""
            printfn $"{timeZone.StandardName} Adjustment rules"

            // Iterate adjustment rules
            for adjustment in adjustments do
                if showCount then
                    printfn $"   Adjustment rule #{ctr + 1}"
                    ctr <- ctr + 1
                // Display general adjustment information
                printfn $"{spacer}   Start Date: {adjustment.DateStart:D}"
                printfn $"{spacer}   End Date: {adjustment.DateEnd:D}"
                printfn $"{spacer}   Time Change: {adjustment.DaylightDelta.Hours}:{adjustment.DaylightDelta.Minutes:D2} hours"
                // Get transition start information
                let transitionStart = adjustment.DaylightTransitionStart
                printf $"{spacer}   Annual Start: "
                if transitionStart.IsFixedDateRule then
                    printfn $"On {monthNames[transitionStart.Month - 1]} {transitionStart.Day} at {transitionStart.TimeOfDay:t}"
                else
                    printfn $"The {transitionStart.Week |> enum<WeekOfMonth>} {transitionStart.DayOfWeek} of {monthNames[transitionStart.Month - 1]} at {transitionStart.TimeOfDay:t}"
                // Get transition end information
                let transitionEnd = adjustment.DaylightTransitionEnd
                printf $"{spacer}   Annual End: "
                if transitionEnd.IsFixedDateRule then
                    printfn $"On {monthNames[transitionEnd.Month - 1]} {transitionEnd.Day} at {transitionEnd.TimeOfDay:t}"
                else
                    printfn $"The {enum<WeekOfMonth> transitionEnd.Week} {transitionEnd.DayOfWeek} of {monthNames[transitionEnd.Month - 1]} at {transitionEnd.TimeOfDay:t}" 
        Console.WriteLine()
Private Enum WeekOfMonth As Integer
   First = 1
   Second = 2
   Third = 3
   Fourth = 4
   Last = 5
End Enum

Private Sub ShowStartAndEndDates()
   ' Get all time zones from system
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   ' Get each time zone
   For Each timeZone As TimeZoneInfo In timeZones
      Dim adjustments() As TimeZoneInfo.AdjustmentRule = timeZone.GetAdjustmentRules()
      ' Display message for time zones with no adjustments
      If adjustments.Length = 0 Then
         Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName)
      Else
         ' Handle time zones with 1 or 2+ adjustments differently
         Dim showCount As Boolean = False
         Dim ctr As Integer = 0
         Dim spacer As String = ""
         
         Console.WriteLine("{0} Adjustment rules", timeZone.StandardName)
         If adjustments.Length > 1 Then showCount = True : spacer = "   "  
         ' Iterate adjustment rules
         For Each adjustment As TimeZoneInfo.AdjustmentRule in adjustments
            If showCount Then 
               Console.WriteLine("   Adjustment rule #{0}", ctr+1)
               ctr += 1
            End If
            ' Display general adjustment information
            Console.WriteLine("{0}   Start Date: {1:D}", spacer, adjustment.DateStart)
            Console.WriteLine("{0}   End Date: {1:D}", spacer, adjustment.DateEnd)
            Console.WriteLine("{0}   Time Change: {1}:{2:00} hours", spacer, _
                              adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes)
            ' Get transition start information
            Dim transitionStart As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionStart
            Console.Write("{0}   Annual Start: ", spacer)
            If transitionStart.IsFixedDateRule Then
               Console.WriteLine("On {0} {1} at {2:t}", _
                                 MonthName(transitionStart.Month), _
                                 transitionStart.Day, _
                                 transitionStart.TimeOfDay)
            Else
               Console.WriteLine("The {0} {1} of {2} at {3:t}", _
                                 CType(transitionStart.Week, WeekOfMonth).ToString(), _
                                 transitionStart.DayOfWeek.ToString(), _
                                 MonthName(transitionStart.Month), _
                                 transitionStart.TimeOfDay)
            End If
            ' Get transition end information
            Dim transitionEnd As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionEnd
                              
            Console.Write("{0}   Annual End: ", spacer)
            If transitionEnd.IsFixedDateRule Then
               Console.WriteLine("On {0} {1} at {2:t}", _
                                 MonthName(transitionEnd.Month), _
                                 transitionEnd.Day, _
                                 transitionEnd.TimeOfDay)
            Else
               Console.WriteLine("The {0} {1} of {2} at {3:t}", _
                                 CType(transitionEnd.Week, WeekOfMonth).ToString(), _
                                 transitionEnd.DayOfWeek.ToString(), _
                                 MonthName(transitionEnd.Month), _
                                 transitionEnd.TimeOfDay)
            End If
         Next
      End If   
      Console.WriteLine()
   Next 
End Sub

설명

메서드는 GetAdjustmentRules 개체 배열 System.TimeZoneInfo.AdjustmentRule 을 검색합니다. 배열의 각 개체는 해당 표준 시간대 조정의 유효 시작 및 종료 날짜와 해당 델타(조정으로 인해 시간이 변경되는 정확한 크기)를 정의합니다. 또한 두 속성은 표준 시간으로의 각 연간 전환이 발생하는 시기를 정의하는 개체를 반환 System.TimeZoneInfo.TransitionTime 합니다.

표준 시간대에 여러 조정 규칙이 있는 경우 일반적으로 초기(인덱스 0)에서 최신(인덱스 Length - 1)으로 정렬됩니다.

표준 시간대에 조정 규칙이 GetAdjustmentRules 없는 경우 메서드는 빈 배열(0인 Length 배열)을 반환합니다.

메서드에서 반환 GetAdjustmentRules 된 배열 요소에 대한 수정 사항은 특정 표준 시간대에 속하는 조정 규칙에 반영되지 않습니다. 표준 시간대의 조정 규칙(예: 일광 절약 시간제로의 이전을 반영)을 수정하려면 기존 조정 규칙을 수정하는 대신 적절한 조정 규칙을 사용하여 새 표준 시간대를 만들어야 합니다.

적용 대상

추가 정보