TimeZoneInfo.GetSystemTimeZones 메서드

정의

로컬 시스템에서 사용할 수 있는 정보에 대한 모든 정렬된 표준 시간대 컬렉션을 반환합니다.Returns a sorted collection of all the time zones about which information is available on the local system.

public:
 static System::Collections::ObjectModel::ReadOnlyCollection<TimeZoneInfo ^> ^ GetSystemTimeZones();
public static System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ();
[System.Security.SecurityCritical]
[System.Security.SecurityTreatAsSafe]
public static System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ();
static member GetSystemTimeZones : unit -> System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>
[<System.Security.SecurityCritical>]
[<System.Security.SecurityTreatAsSafe>]
static member GetSystemTimeZones : unit -> System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>
Public Shared Function GetSystemTimeZones () As ReadOnlyCollection(Of TimeZoneInfo)

반환

ReadOnlyCollection<TimeZoneInfo>

TimeZoneInfo 개체의 읽기 전용 컬렉션입니다.A read-only collection of TimeZoneInfo objects.

특성

예외

모든 표준 시간대 정보를 저장할 메모리가 부족한 경우There is insufficient memory to store all time zone information.

표준 시간대 정보가 포함된 레지스트리 키를 읽을 권한이 사용자에게 없는 경우The user does not have permission to read from the registry keys that contain time zone information.

예제

다음 예제에서는 컴퓨터에 정의 된 표준 시간대를 나타내는 표준 시간대 개체의 컬렉션을 검색 하 고 해당 표준 시간대에 대 한 정보를 텍스트 파일에 기록 합니다.The following example retrieves a collection of time zone objects that represent the time zones defined on a computer and writes information about them to a text file.

using System;
using System.Globalization;
using System.IO;
using System.Collections.ObjectModel;

public class Example
{
   public static void Main()
   {
      const string OUTPUTFILENAME = @"C:\Temp\TimeZoneInfo.txt";
   
      DateTimeFormatInfo dateFormats = CultureInfo.CurrentCulture.DateTimeFormat;
      ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); 
      StreamWriter sw = new StreamWriter(OUTPUTFILENAME, false);
   
      foreach (TimeZoneInfo timeZone in timeZones)
      {
         bool hasDST = timeZone.SupportsDaylightSavingTime;
         TimeSpan offsetFromUtc = timeZone.BaseUtcOffset;
         TimeZoneInfo.AdjustmentRule[] adjustRules;
         string offsetString;
      
         sw.WriteLine("ID: {0}", timeZone.Id);
         sw.WriteLine("   Display Name: {0, 40}", timeZone.DisplayName);
         sw.WriteLine("   Standard Name: {0, 39}", timeZone.StandardName);
         sw.Write("   Daylight Name: {0, 39}", timeZone.DaylightName);
         sw.Write(hasDST ? "   ***Has " : "   ***Does Not Have ");
         sw.WriteLine("Daylight Saving Time***");
         offsetString = String.Format("{0} hours, {1} minutes", offsetFromUtc.Hours, offsetFromUtc.Minutes);
         sw.WriteLine("   Offset from UTC: {0, 40}", offsetString);
         adjustRules = timeZone.GetAdjustmentRules();
         sw.WriteLine("   Number of adjustment rules: {0, 26}", adjustRules.Length);  
         if (adjustRules.Length > 0)
         {
            sw.WriteLine("   Adjustment Rules:");
            foreach (TimeZoneInfo.AdjustmentRule rule in adjustRules)
            {
               TimeZoneInfo.TransitionTime transTimeStart = rule.DaylightTransitionStart;
               TimeZoneInfo.TransitionTime transTimeEnd = rule.DaylightTransitionEnd; 
            
               sw.WriteLine("      From {0} to {1}", rule.DateStart, rule.DateEnd);
               sw.WriteLine("      Delta: {0}", rule.DaylightDelta);
               if (! transTimeStart.IsFixedDateRule)
               {
                  sw.WriteLine("      Begins at {0:t} on {1} of week {2} of {3}", transTimeStart.TimeOfDay, 
                                                                                transTimeStart.DayOfWeek,                                                                                 
                                                                                transTimeStart.Week, 
                                                                                dateFormats.MonthNames[transTimeStart.Month - 1]);
                  sw.WriteLine("      Ends at {0:t} on {1} of week {2} of {3}", transTimeEnd.TimeOfDay,
                                                                                transTimeEnd.DayOfWeek, 
                                                                                transTimeEnd.Week,
                                                                                dateFormats.MonthNames[transTimeEnd.Month - 1]);
               }
               else
               {
                  sw.WriteLine("      Begins at {0:t} on {1} {2}", transTimeStart.TimeOfDay, 
                                                                 transTimeStart.Day, 
                                                                 dateFormats.MonthNames[transTimeStart.Month - 1]);
                  sw.WriteLine("      Ends at {0:t} on {1} {2}", transTimeEnd.TimeOfDay, 
                                                               transTimeEnd.Day, 
                                                               dateFormats.MonthNames[transTimeEnd.Month - 1]);
               }
            }
         }            
      }
      sw.Close();
   }
}
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.IO

Module Example
   Public Sub Main()
      Const OUTPUTFILENAME As String = "C:\Temp\TimeZoneInfo.txt"
      
      Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones() 
      Dim sw As StreamWriter = New StreamWriter(OUTPUTFILENAME, False)
      
      For Each timeZone As TimeZoneInfo in timeZones
         Dim hasDST As Boolean = timeZone.SupportsDaylightSavingTime
         Dim offsetFromUtc As TimeSpan = timeZone.BaseUtcOffset
         Dim adjustRules() As System.TimeZoneInfo.AdjustmentRule
         Dim offsetString As String
         
         sw.WriteLine("ID: {0}", timeZone.Id)
         sw.WriteLine("   Display Name: {0, 40}", timeZone.DisplayName)
         sw.WriteLine("   Standard Name: {0, 39}", timeZone.StandardName)
         sw.Write("   Daylight Name: {0, 39}", timeZone.DaylightName)
         sw.Write(iif(hasDST, "   ***Has ", "   ***Does Not Have "))
         sw.WriteLine("Daylight Saving Time***")
         offsetString = String.Format("{0} hours, {1} minutes", offsetFromUtc.Hours, offsetFromUtc.Minutes)
         sw.WriteLine("   Offset from UTC: {0, 40}", offsetString)
         adjustRules = timeZone.GetAdjustmentRules()
         sw.WriteLine("   Number of adjustment rules: {0, 26}", adjustRules.Length)  
         If adjustRules.Length > 0 Then
            sw.WriteLine("   Adjustment Rules:")
            For Each rule As TimeZoneInfo.AdjustmentRule In adjustRules
               Dim transTimeStart As TimeZoneInfo.TransitionTime = rule.DaylightTransitionStart
               Dim transTimeEnd As TimeZoneInfo.TransitionTime = rule.DaylightTransitionEnd 
               
               sw.WriteLine("      From {0} to {1}", rule.DateStart, rule.DateEnd)
               sw.WriteLine("      Delta: {0}", rule.DaylightDelta)
               If Not transTimeStart.IsFixedDateRule
                  sw.WriteLine("      Begins at {0:t} on {1} of week {2} of {3}", transTimeStart.TimeOfDay, _
                                                                                transTimeStart.DayOfWeek, _
                                                                                transTimeStart.Week, _
                                                                                MonthName(transTimeStart.Month))
                  sw.WriteLine("      Ends at {0:t} on {1} of week {2} of {3}", transTimeEnd.TimeOfDay, _
                                                                                transTimeEnd.DayOfWeek, _
                                                                                transTimeEnd.Week, _
                                                                                MonthName(transTimeEnd.Month))
               Else
                  sw.WriteLine("      Begins at {0:t} on {1} {2}", transTimeStart.TimeOfDay, _
                                                                 transTimeStart.Day, _
                                                                 MonthName(transTimeStart.Month))
                  sw.WriteLine("      Ends at {0:t} on {1} {2}", transTimeEnd.TimeOfDay, _
                                                               transTimeEnd.Day, _
                                                               MonthName(transTimeEnd.Month))
               End If
            Next
         End If            
      Next
      sw.Close()
#  Get timezone/date details and open a stream writer
$DateFormats    = [System.Globalization.CultureInfo]::CurrentCulture.DateTimeFormat
$TimeZones      = [System.TimeZoneInfo]::GetSystemTimeZones()
$OutputFileName = 'C:\Temp\TimeZoneInfo.txt'
$Sw             = New-Object -TypeName System.IO.StreamWriter -ArgumentList $OutputFileName,$false
# Write overview information
$Sw.WriteLine('{0} Time zones on this system' -f $TimeZones.Count)

# Process each timezone on the system
# Write details to the streamwriter
foreach ($TimeZone in $TimeZones) {
 $HasDST        = $TimeZone.SupportsDaylightSavingTime
 $OffsetFromUtc = $TimeZone.BaseUtcOffset
 $Sw.WriteLine("ID: {0}" -f $TimeZone.Id)
 $Sw.WriteLine("   Display Name:  {0}" -f $TimeZone.DisplayName)
 $Sw.WriteLine("   Standard Name: {0}" -f $TimeZone.StandardName)
 $Sw.Write("   Daylight Name: {0}" -f $TimeZone.DaylightName)
 $Sw.Write( $(If ($HasDST) {"  ***Has: "} Else {"  ***Does Not Have: "}))
 $Sw.WriteLine("Daylight Saving Time***")
 $OffsetString = "{0} hours, {1} minutes" -f $OffsetFromUtc.Hours, $OffsetFromUtc.Minutes
 $Sw.WriteLine("   Offset from UTC: {0}"  -f $offsetString)
 $AdjustRules = $timeZone.GetAdjustmentRules()
 $Sw.WriteLine("   Number of adjustment rules: {0}" -f $adjustRules.Count)
 If ($AdjustRules.Count -gt 0)
 {
    $Sw.WriteLine("   Adjustment Rules:")
    foreach ($Rule in $AdjustRules)
    {
       $TransTimeStart = $Rule.DaylightTransitionStart
       $TransTimeEnd   = $Rule.DaylightTransitionEnd
       $Sw.WriteLine(("     From   {0} to {1}" -f $Rule.DateStart, $Rule.DateEnd))
       $Sw.WriteLine(("       Delta: {0}" -f $Rule.DaylightDelta))
       if (-Not  $TransTimeStart.IsFixedDateRule)
       {
          $Sw.WriteLine(("       Begins at {0:t} on {1} of week {2} of {3}" -f $TransTimeStart.TimeOfDay, 
                                                                             $TransTimeStart.DayOfWeek,                                                                                 
                                                                             $TransTimeStart.Week, 
                                                                             $DateFormats.MonthNames[$TransTimeStart.Month - 1]))
          $Sw.WriteLine(("       Ends at {0:t} on {1} of week {2} of {3}" -f $TransTimeEnd.TimeOfDay,
                                                                             $TransTimeEnd.DayOfWeek, 
                                                                             $TransTimeEnd.Week,
                                                                             $DateFormats.MonthNames[[int] $TransTimeEnd.Month - 1]))
       }
     else
       {
         $Sw.WriteLine(("       Begins at {0:t} on {1} {2}" -f $TransTimeStart.TimeOfDay, 
                                                             $TransTimeStart.Day, 
                                                             $DateFormats.MonthNames[$transTimeStart.Month - 1]))
         $Sw.WriteLine(("       Ends at {0:t} on {1} {2}"   -f $TransTimeEnd.TimeOfDay, 
                                                             $TransTimeEnd.Day, 
                                                             $DateFormats.MonthNames[$transTimeEnd.Month - 1]))        
       }
    } # End of processing each adjustment rule
 } # End of checking adjustment rules
} # End of processing Time Zones

# Close stream writer then display output in notepad
$Sw.Close() 

#  Output of 1st three time zones:
#  135 Time zones on this system
#  ID: Dateline Standard Time
#     Display Name:  (UTC-12:00) International Date Line West
#     Standard Name: Dateline Standard Time
#     Daylight Name: Dateline Summer Time  ***Does Not Have: Daylight Saving Time***
#     Offset from UTC: -12 hours, 0 minutes
#     Number of adjustment rules: 0
#  ID: UTC-11
#     Display Name:  (UTC-11:00) Co-ordinated Universal Time-11
#     Standard Name: UTC-11
#     Daylight Name: UTC-11  ***Does Not Have: Daylight Saving Time***
#     Offset from UTC: -11 hours, 0 minutes
#     Number of adjustment rules: 0
#  ID: Aleutian Standard Time
#     Display Name:  (UTC-10:00) Aleutian Islands
#     Standard Name: Aleutian Standard Time
#     Daylight Name: Aleutian Summer Time  ***Has: Daylight Saving Time***
#     Offset from UTC: -10 hours, 0 minutes
#     Number of adjustment rules: 2
#     Adjustment Rules:
#       From   01/01/0001 00:00:00 to 31/12/2006 00:00:00
#         Delta: 01:00:00
#         Begins at 02:00 on Sunday of week 1 of April
#         Ends at 02:00 on Sunday of week 5 of October
#       From   01/01/2007 00:00:00 to 31/12/9999 00:00:00
#         Delta: 01:00:00
#         Begins at 02:00 on Sunday of week 2 of March
#         Ends at 02:00 on Sunday of week 1 of November

설명

GetSystemTimeZones메서드는 Windows 시스템에서 레지스트리 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones 키의 하위 키와 Linux 및 macOS의 ICU 라이브러리 에서 사용 가능한 표준 시간대 정보를 모두 검색 합니다.The GetSystemTimeZones method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the ICU Library on Linux and macOS. 개별 개체의 특정 문자열 속성에 대 한 값을 성공적으로 검색 하 고 구문 분석할 수 없는 경우 TimeZoneInfo 이 메서드는 해당 값을 빈 문자열 ("")로 설정 합니다.If it is unable to successfully retrieve and parse values for particular string properties of individual TimeZoneInfo objects, this method sets their value to an empty string ("").

중요

GetSystemTimeZones메서드는 TimeZoneInfo Windows 레지스트리 또는 ICU 라이브러리에 정의 된 표준 시간대에 대해서만 개체의 컬렉션을 반환 합니다.The GetSystemTimeZones method returns a collection of TimeZoneInfo objects only for time zones defined in the Windows registry or the ICU library. 메서드의 오버 로드를 사용 하 여 만든 표준 시간대는 포함 되지 않습니다 CreateCustomTimeZone .It does not include time zones created using the overloads of the CreateCustomTimeZone method. 표준 시간대 생성 방법에서 반환 되는 개체 참조를 통해서만 액세스할 수 있습니다.These are accessible only through the object reference returned by the time zone creation method.

이 메서드에서 반환 하는 컬렉션은 UTC 오프셋을 기준으로 정렬 되며 UTC 오프셋이 동일한 표준 시간대의 경우 현재 문화권을 사용 하 여 표시 이름을 기준으로 정렬 됩니다.The collection returned by this method is sorted by UTC offset and, for time zones that have the same UTC offset, by the display name using the current culture. 표시 이름에 대 한 자세한 내용은을 참조 하십시오 DisplayName .For information about the display name, see DisplayName.

ReadOnlyCollection<T>이 메서드에서 반환 하는 개체는 IEnumerable<T> 인터페이스를 지원 합니다. 즉, foreach (c #의 경우) 또는 For Each…Next (Visual Basic) 문을 사용 하 여이를 반복할 수 있습니다.The ReadOnlyCollection<T> object returned by this method supports the IEnumerable<T> interface, which means that it can be iterated using the foreach (in C#) or For Each…Next (in Visual Basic) statements. 루프의 각 반복은 컬렉션의 다음 개체를 제공 합니다 TimeZoneInfo .Each iteration of the loop provides the next TimeZoneInfo object in the collection.

개체의 컬렉션은 TimeZoneInfo 로컬 컴퓨터에 정의 된 표준 시간대를 나타내지만 모든 기간 동안 모든 표준 시간대에 대 한 완전 한 정보를 제공 하지는 않습니다.The collection of TimeZoneInfo objects represents time zones defined on the local computer; it does not necessarily provide complete information for all time zones during all time periods. 애플리케이션에서 로컬 컴퓨터에 없는 표준 시간대에 필요한 경우에 오버 로드를 사용 하 여 사용자 지정 시간 영역을 만들 수 있습니다는 CreateCustomTimeZone 메서드.If your application requires time zones not found on the local computer, you can create custom time zones using the overloads of the CreateCustomTimeZone method. 자세한 내용은 방법: 조정 규칙을 사용 하지 않고 표준 시간대 만들기방법: 조정 규칙을 사용 하 여 표준시간대 만들기를 참조 하세요.For more information, see How to: Create Time Zones Without Adjustment Rules and How to: Create Time Zones with Adjustment Rules.

또한 메서드를 호출 하 FindSystemTimeZoneById 고 매개 변수로 검색할 표준 시간대의 식별자를 제공 하 여 로컬 컴퓨터에 개별 표준 시간대가 정의 되어 있는지 여부를 확인할 수 있습니다.You can also determine whether an individual time zone is defined on the local computer by calling the FindSystemTimeZoneById method and providing the identifier of the time zone you want to retrieve as a parameter.

적용 대상