TimeZoneInfo.TransitionTime.IsFixedDateRule TimeZoneInfo.TransitionTime.IsFixedDateRule TimeZoneInfo.TransitionTime.IsFixedDateRule TimeZoneInfo.TransitionTime.IsFixedDateRule Property

定義

時刻の変更が、固定された日時 (たとえば、11 月 1 日) に発生するか、またはフローティング日時 (たえとば、10 月の最後の日曜日) に発生するかを示す値を取得します。Gets a value indicating whether the time change occurs at a fixed date and time (such as November 1) or a floating date and time (such as the last Sunday of October).

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

プロパティ値

時刻の変更ルールが固定された日付の場合は true。時刻の変更ルールがフローティング日付の場合は falsetrue if the time change rule is fixed-date; false if the time change rule is floating-date.

次の例では、ローカル システムで利用できるすべてのタイム ゾーンの遷移時間と夏時間の間が一覧表示します。The following example lists the transition times to and from daylight saving time for all time zones that are available on the local system. 固定日付の規則のタイム ゾーン、のプロパティからの移行時間の情報が表示されます、TimeZoneInfo.TransitionTimeオブジェクト。For time zones with fixed-date rules, it displays transition time information from the properties of the TimeZoneInfo.TransitionTime object. 固定日付の規則のないタイム ゾーンを使用して、Calendar遷移の実際の開始と終了日を判断する現在のシステム カレンダーを表すオブジェクト。For time zones without fixed-date rules, it uses a Calendar object that represents the current system calendar to determine the actual start and end dates of the transition. コンソールに結果を表示します。The example displays the results to the console.

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);   
}   
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   

注釈

固定日付の規則では、同じ日付と時刻の調整規則を適用するには、各年の切り替えが発生することを示します。A fixed-date rule indicates that the transition occurs on the same date and time of each year to which the adjustment rule applies. たとえば、毎年 11 月 3日が発生する時間変更では、固定日付の規則に従います。For example, a time change that occurs every November 3 follows a fixed-date rule. フローティング日付規則では、特定の調整規則を適用する各年の月の特定の週の特定の日に切り替えが発生することを示します。A floating-date rule indicates that the transition occurs on a specific day of a specific week of a specific month for each year to which the adjustment rule applies. たとえば、年 11 月の最初の日曜日に発生する時間変更では、フローティング日付規則に従います。For example, a time change that occurs on the first Sunday of November follows a floating-date rule.

値、IsFixedDateRuleプロパティのプロパティを決定します、TimeZoneInfo.TransitionTimeオブジェクトが有効な値を指定します。The value of the IsFixedDateRule property determines which properties of a TimeZoneInfo.TransitionTime object have valid values. 次の表では、プロパティがの値によって影響を受けることを示します、IsFixedDateRuleプロパティ。The following table indicates which properties are affected by the value of the IsFixedDateRule property.

TransitionTime プロパティTransitionTime property IsFixedDateRule = trueIsFixedDateRule = true IsFixedDateRule = falseIsFixedDateRule = false
Day 有効Valid 未使用Unused
DayOfWeek 未使用Unused 有効Valid
Week 未使用Unused 有効Valid
Month 有効Valid 有効Valid
TimeOfDay 有効Valid 有効Valid

適用対象