다음을 통해 공유


TimeZoneInfo.TransitionTime.IsFixedDateRule 속성

정의

시간 변경이 고정 날짜 및 시간(예: 11월 1일)에 발생하는지, 아니면 부동 날짜 및 시간(예: 10월의 마지막 일요일)에 발생하는지를 나타내는 값을 가져옵니다.

public:
 property bool IsFixedDateRule { bool get(); };
public bool IsFixedDateRule { get; }
member this.IsFixedDateRule : bool
Public ReadOnly Property IsFixedDateRule As Boolean

속성 값

Boolean

시간 변경 규칙이 고정 날짜이면 true이고, 시간 변경 규칙이 부동 날짜이면 false입니다.

예제

다음 예제에서는 로컬 시스템에서 사용할 수 있는 모든 표준 시간대의 일광 절약 시간에서 전환 시간을 나열합니다. 고정 날짜 규칙이 있는 표준 시간대의 경우 개체의 TimeZoneInfo.TransitionTime 속성에서 전환 시간 정보를 표시합니다. 고정 날짜 규칙이 없는 표준 시간대의 경우 현재 시스템 달력을 Calendar 나타내는 개체를 사용하여 전환의 실제 시작 및 종료 날짜를 결정합니다. 이 예제에서는 콘솔에 결과를 표시합니다.

private void GetTransitionTimes(int year)
{
   // Instantiate DateTimeFormatInfo object for month names
   DateTimeFormatInfo dateFormat = CultureInfo.CurrentCulture.DateTimeFormat;

   // Get and iterate time zones on local computer
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   foreach (TimeZoneInfo timeZone in timeZones)
   {
      Console.WriteLine("{0}:", timeZone.StandardName);
      TimeZoneInfo.AdjustmentRule[] adjustments = timeZone.GetAdjustmentRules();
      int startYear = year;
      int endYear = startYear;

      if (adjustments.Length == 0)
      {
         Console.WriteLine("   No adjustment rules.");
      }   
      else
      {   
         TimeZoneInfo.AdjustmentRule adjustment = GetAdjustment(adjustments, year);
         if (adjustment == null)
         {
            Console.WriteLine("   No adjustment rules available for this year.");
            continue;
         }
         TimeZoneInfo.TransitionTime startTransition, endTransition;
         
         // Determine if starting transition is fixed 
         startTransition = adjustment.DaylightTransitionStart;
         // Determine if starting transition is fixed and display transition info for year
         if (startTransition.IsFixedDateRule)
            Console.WriteLine("   Begins on {0} {1} at {2:t}", 
                              dateFormat.GetMonthName(startTransition.Month), 
                              startTransition.Day, 
                              startTransition.TimeOfDay);
         else
            DisplayTransitionInfo(startTransition, startYear, "Begins on");

         // Determine if ending transition is fixed and display transition info for year
         endTransition = adjustment.DaylightTransitionEnd;
         
         // Does the transition back occur in an earlier month (i.e., 
         // the following year) than the transition to DST? If so, make
         // sure we have the right adjustment rule.
         if (endTransition.Month < startTransition.Month)
         {
            endTransition = GetAdjustment(adjustments, year + 1).DaylightTransitionEnd;
            endYear++;
         }
      
         if (endTransition.IsFixedDateRule)
            Console.WriteLine("   Ends on {0} {1} at {2:t}", 
                              dateFormat.GetMonthName(endTransition.Month), 
                              endTransition.Day, 
                              endTransition.TimeOfDay);
         else
            DisplayTransitionInfo(endTransition, endYear, "Ends on");
      }      
   }   
} 

private static TimeZoneInfo.AdjustmentRule GetAdjustment(TimeZoneInfo.AdjustmentRule[] adjustments,
                                                  int year)
{                                                  
   // Iterate adjustment rules for time zone
   foreach (TimeZoneInfo.AdjustmentRule adjustment in adjustments)
   {
      // Determine if this adjustment rule covers year desired
      if (adjustment.DateStart.Year <= year && adjustment.DateEnd.Year >= year)
         return adjustment;
   }   
   return null;
}

private void DisplayTransitionInfo(TimeZoneInfo.TransitionTime transition, int year, string label)
{
   // For non-fixed date rules, get local calendar
   Calendar cal = CultureInfo.CurrentCulture.Calendar;
   // Get first day of week for transition
   // For example, the 3rd week starts no earlier than the 15th of the month
   int startOfWeek = transition.Week * 7 - 6;
   // What day of the week does the month start on?
   int firstDayOfWeek = (int) cal.GetDayOfWeek(new DateTime(year, transition.Month, 1)); 
   // Determine how much start date has to be adjusted
   int transitionDay; 
   int changeDayOfWeek = (int) transition.DayOfWeek;

   if (firstDayOfWeek <= changeDayOfWeek)
      transitionDay = startOfWeek + (changeDayOfWeek - firstDayOfWeek);
   else     
      transitionDay = startOfWeek + (7 - firstDayOfWeek + changeDayOfWeek);

   // Adjust for months with no fifth week
   if (transitionDay > cal.GetDaysInMonth(year, transition.Month))  
      transitionDay -= 7;

   Console.WriteLine("   {0} {1}, {2:d} at {3:t}", 
                     label, 
                     transition.DayOfWeek, 
                     new DateTime(year, transition.Month, transitionDay), 
                     transition.TimeOfDay);   
}
open System
open System.Globalization

let displayTransitionInfo (transition: TimeZoneInfo.TransitionTime) year label =
    // For non-fixed date rules, get local calendar
    let cal = CultureInfo.CurrentCulture.Calendar
    // Get first day of week for transition
    // For example, the 3rd week starts no earlier than the 15th of the month
    let startOfWeek = transition.Week * 7 - 6
    // What day of the week does the month start on?
    let firstDayOfWeek = cal.GetDayOfWeek(DateTime(year, transition.Month, 1)) |> int 
    // Determine how much start date has to be adjusted
    let changeDayOfWeek = int transition.DayOfWeek

    let transitionDay = 
        if firstDayOfWeek <= changeDayOfWeek then
            startOfWeek + (changeDayOfWeek - firstDayOfWeek)
        else     
            startOfWeek + (7 - firstDayOfWeek + changeDayOfWeek)

    // Adjust for months with no fifth week
    let transitionDay =
        if transitionDay > cal.GetDaysInMonth(year, transition.Month) then  
            transitionDay - 7
        else 
            transitionDay

    printfn $"   {label} {transition.DayOfWeek}, {DateTime(year, transition.Month, transitionDay):d} at {transition.TimeOfDay:t}"   

let getAdjustment (adjustments: TimeZoneInfo.AdjustmentRule seq) year =
    adjustments
    // Iterate adjustment rules for time zone
    // Determine if this adjustment rule covers year desired
    |> Seq.tryFind (fun adjustment -> adjustment.DateStart.Year <= year && adjustment.DateEnd >= DateTime year)
    |> Option.defaultValue null

let getTransitionTimes year =
    // Instantiate DateTimeFormatInfo object for month names
    let dateFormat = CultureInfo.CurrentCulture.DateTimeFormat

    // Get and iterate time zones on local computer
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    for timeZone in timeZones do
        printfn $"{timeZone.StandardName}:"
        let adjustments = timeZone.GetAdjustmentRules()
        let startYear = year
        let mutable endYear = startYear

        if adjustments.Length = 0 then
            printfn "   No adjustment rules."
        else
            let adjustment = getAdjustment adjustments year
            if adjustment = null then
                Console.WriteLine("   No adjustment rules available for this year.")
            else
                // Determine if starting transition is fixed 
                let startTransition = adjustment.DaylightTransitionStart
                // Determine if starting transition is fixed and display transition info for year
                if startTransition.IsFixedDateRule then
                    printfn $"   Begins on {dateFormat.GetMonthName startTransition.Month} {startTransition.Day} at {startTransition.TimeOfDay:t}"
                else
                    displayTransitionInfo startTransition startYear "Begins on"

                // Determine if ending transition is fixed and display transition info for year
                let mutable endTransition = adjustment.DaylightTransitionEnd
                
                // Does the transition back occur in an earlier month (i.e., 
                // the following year) than the transition to DST? If so, make
                // sure we have the right adjustment rule.
                if endTransition.Month < startTransition.Month then
                    endTransition <- (getAdjustment adjustments (year + 1)).DaylightTransitionEnd
                    endYear <- endYear + 1
                
                if endTransition.IsFixedDateRule then
                    printfn $"   Ends on {dateFormat.GetMonthName endTransition.Month} {endTransition.Day} at {endTransition.TimeOfDay:t}"
                else
                    displayTransitionInfo endTransition endYear "Ends on"
Private Sub GetTransitionTimes(year As Integer)
   ' Get and iterate time zones on local computer
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   For Each timeZone As TimeZoneInfo In timeZones
      Console.WriteLine("{0}:", timeZone.StandardName)
      Dim adjustments() As TimeZoneInfo.AdjustmentRule = timeZone.GetAdjustmentRules()
      Dim startYear As Integer = year
      Dim endYear As Integer = startYear

      If adjustments.Length = 0 Then
         Console.WriteLine("   No adjustment rules.")
      Else   
         Dim adjustment As TimeZoneInfo.AdjustmentRule = GetAdjustment(adjustments, year)
         If adjustment Is Nothing Then
            Console.WriteLine("   No adjustment rules available for this year.")
            Continue For
         End If
         Dim startTransition, endTransition As TimeZoneInfo.TransitionTime

         ' Determine if starting transition is fixed 
         startTransition = adjustment.DaylightTransitionStart
         ' Determine if starting transition is fixed and display transition info for year
         If startTransition.IsFixedDateRule Then
            Console.WriteLine("   Begins on {0} {1} at {2:t}", _
                              MonthName(startTransition.Month), _
                              startTransition.Day, _
                              startTransition.TimeOfDay)
         Else
            DisplayTransitionInfo(startTransition, startYear, "Begins on")
         End If    

         ' Determine if ending transition is fixed and display transition info for year
         endTransition = adjustment.DaylightTransitionEnd
                
         ' Does the transition back occur in an earlier month (i.e., 
         ' the following year) than the transition to DST? If so, make
         ' sure we have the right adjustment rule.
         If endTransition.Month < startTransition.Month Then
            endTransition = GetAdjustment(adjustments, year + 1).DaylightTransitionEnd
            endYear += 1
         End If

         If endTransition.IsFixedDateRule Then
            Console.WriteLine("   Ends on {0} {1} at {2:t}", _
                              MonthName(endTransition.Month), _
                              endTransition.Day, _
                              endTransition.TimeOfDay)
         Else
            DisplayTransitionInfo(endTransition, endYear, "Ends on")
         End If    
      End If   
   Next 
End Sub

Private Function GetAdjustment(adjustments As TimeZoneInfo.AdjustmentRule(), _
                               year As Integer) As TimeZoneInfo.AdjustmentRule
   ' Iterate adjustment rules for time zone
   For Each adjustment As TimeZoneInfo.AdjustmentRule In adjustments
      ' Determine if this adjustment rule covers year desired
      If adjustment.DateStart.Year <= year And adjustment.DateEnd.Year >= year Then
         Return adjustment
      End If
   Next   
   Return Nothing
End Function
   
Private Sub DisplayTransitionInfo(transition As TimeZoneInfo.TransitionTime, year As Integer, label As String)
   ' For non-fixed date rules, get local calendar
   Static cal As Calendar = CultureInfo.CurrentCulture.Calendar

   ' Get first day of week for transition
   ' For example, the 3rd week starts no earlier than the 15th of the month
   Dim startOfWeek As Integer = transition.Week * 7 - 6
   ' What day of the week does the month start on?
   Dim firstDayOfWeek As Integer = cal.GetDayOfWeek(New Date(year, transition.Month, 1))
   ' Determine how much start date has to be adjusted
   Dim transitionDay As Integer 
   Dim changeDayOfWeek As Integer = transition.DayOfWeek

   If firstDayOfWeek <= changeDayOfWeek Then
      transitionDay = startOfWeek + (changeDayOfWeek - firstDayOfWeek)
   Else     
      transitionDay = startOfWeek + (7 - firstDayOfWeek + changeDayOfWeek)
   End If
   ' Adjust for months with no fifth week
   If transitionDay > cal.GetDaysInMonth(year, transition.Month) Then  
      transitionDay -= 7
   End If
   Console.WriteLine("   {0} {1}, {2:d} at {3:t}", _
                     label, _
                     transition.DayOfWeek, _
                     New DateTime(year, transition.Month, transitionDay), _
                     transition.TimeOfDay)   
End Sub

설명

고정 날짜 규칙은 조정 규칙이 적용되는 각 연도의 동일한 날짜 및 시간에 전환이 발생한다는 것을 나타냅니다. 예를 들어 11월 3일마다 발생하는 시간 변경은 고정 날짜 규칙을 따릅니다. 부동 날짜 규칙은 조정 규칙이 적용되는 각 연도의 특정 월의 특정 요일에 전환이 발생한다는 것을 나타냅니다. 예를 들어 11월 첫 번째 일요일에 발생하는 시간 변경은 부동 날짜 규칙을 따릅니다.

속성 값은 IsFixedDateRule 유효한 값이 있는 TimeZoneInfo.TransitionTime 개체의 속성을 결정합니다. 다음 표에서는 속성 값의 IsFixedDateRule 영향을 받는 속성을 나타냅니다.

TransitionTime 속성 IsFixedDateRule = true IsFixedDateRule = false
Day Valid 사용 안 함
DayOfWeek 사용 안 함 Valid
Week 사용 안 함 Valid
Month 유효함 유효함
TimeOfDay 유효함 Valid

적용 대상