TimeZoneInfo.GetAdjustmentRules TimeZoneInfo.GetAdjustmentRules TimeZoneInfo.GetAdjustmentRules TimeZoneInfo.GetAdjustmentRules Method

定義

現在の TimeZoneInfo.AdjustmentRule オブジェクトに適用する TimeZoneInfo オブジェクトの配列を取得します。Retrieves an array of TimeZoneInfo.AdjustmentRule objects that apply to the current TimeZoneInfo object.

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

戻り値

このタイム ゾーンのオブジェクトの配列。An array of objects for this time zone.

例外

調整規則のメモリ内コピーを作成するために必要なメモリがシステムにありません。The system does not have enough memory to make an in-memory copy of the adjustment rules.

次の例は、ローカル システム情報を表示します完了について、コンソールにそれらの調整規則で定義されているすべてのタイム ゾーンを取得します。The following example retrieves all time zones that are defined on the local system and displays complete information about their adjustment rules to the console.

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();
   } 
}
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オブジェクト。The GetAdjustmentRules method retrieves an array of System.TimeZoneInfo.AdjustmentRule objects. 配列内の各オブジェクトがそのデルタと同様に、そのタイム ゾーン調整の有効な開始と終了日を定義します (調整を変更する時間のによって使用される正確な量)。Each object in the array defines the effective start and end date of that time zone adjustment, as well as its delta (the exact amount by which the adjustment causes the time to change). さらに、2 つのプロパティが返すSystem.TimeZoneInfo.TransitionTime標準時との間の切り替えが発生したときを定義するオブジェクト。In addition, two properties return System.TimeZoneInfo.TransitionTime objects that define when each annual transition to and from standard time occurs.

タイム ゾーンに複数の調整規則がある場合は、通常、順序がから最も古い (インデックス 0) の最新版に (インデックス位置にあるLength- 1)。If a time zone has multiple adjustment rules, they are generally ordered from earliest (at index 0) to latest (at index Length - 1).

タイム ゾーン調整の規則が存在しない場合、GetAdjustmentRulesメソッドは空の配列を返します (配列のLengthは 0 です)。If a time zone has no adjustment rules, the GetAdjustmentRules method returns an empty array (an array whose Length is zero).

によって返される配列の要素への変更、GetAdjustmentRulesメソッドは、特定のタイム ゾーンに属している調整規則には反映されません。Any modifications to the elements of the array returned by the GetAdjustmentRules method are not reflected in the adjustment rules that belong to a particular time zone. (履歴の遷移と夏時間の間の反映など) のタイム ゾーンの調整規則を変更する必要があります、適切な調整規則では、新しいタイム ゾーンを作成ではなく既存のものを変更します。To modify a time zone's adjustment rules (such as to reflect its historical transition to and from daylight saving time) you must create a new time zone with the appropriate adjustment rules, rather than modify the existing one.

適用対象

こちらもご覧ください