TimeZoneInfo.TransitionTime.IsFixedDateRule プロパティ

定義

時刻の変更が、固定された日時 (たとえば、11 月 1 日) に発生するか、またはフローティング日時 (たえとば、10 月の最後の日曜日) に発生するかを示す値を取得します。

C#
public bool IsFixedDateRule { get; }

プロパティ値

Boolean

時刻の変更ルールが固定された日付の場合は true。時刻の変更ルールがフローティング日付の場合は false

次の例では、ローカル システムで使用できるすべてのタイム ゾーンの夏時間との間の切り替え時間の一覧を示します。 固定日付ルールを持つタイム ゾーンの場合、オブジェクトのプロパティからの遷移時間情報が TimeZoneInfo.TransitionTime 表示されます。 固定日付ルールのないタイム ゾーンでは、現在の Calendar システムカレンダーを表すオブジェクトを使用して、移行の実際の開始日と終了日を決定します。 この例では、結果をコンソールに表示します。

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

注釈

固定日付ルールは、調整ルールが適用される年と同じ日時に切り替えが行われることを示します。 たとえば、毎年 11 月 3 日に発生する時刻の変更は、固定日付ルールに従います。 浮動小数点日付ルールは、調整規則が適用される年ごとに、特定の月の特定の週の特定の日に切り替えが行われることを示します。 たとえば、11 月の最初の日曜日に発生する時刻の変更は、浮動小数点型の規則に従います。

プロパティの値によって、 IsFixedDateRule 有効な値を持つオブジェクトのプロパティが TimeZoneInfo.TransitionTime 決まります。 次の表は、プロパティの値の影響を受けるプロパティを IsFixedDateRule 示しています。

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

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1