TimeZoneInfo.FindSystemTimeZoneById(String) Yöntem

Tanım

TimeZoneInfoKendi tanımlayıcısına göre yeni bir nesne oluşturur.Instantiates a new TimeZoneInfo object based on its identifier.

public:
 static TimeZoneInfo ^ FindSystemTimeZoneById(System::String ^ id);
public static TimeZoneInfo FindSystemTimeZoneById (string id);
static member FindSystemTimeZoneById : string -> TimeZoneInfo
Public Shared Function FindSystemTimeZoneById (id As String) As TimeZoneInfo

Parametreler

id
String

Özelliğe karşılık gelen saat dilimi tanımlayıcısı Id .The time zone identifier, which corresponds to the Id property.

Döndürülenler

TimeZoneInfo

Tanıtıcısı parametresinin değeri olan bir nesne id .An object whose identifier is the value of the id parameter.

Özel durumlar

Sistem, saat dilimi hakkındaki bilgileri tutmak için yeterli belleğe sahip değil.The system does not have enough memory to hold information about the time zone.

idParametresi null .The id parameter is null.

Tarafından belirtilen saat dilimi tanımlayıcısı id bulunamadı.The time zone identifier specified by id was not found. Bu, adı eşleşen bir saat dilimi tanımlayıcısının id mevcut olmadığı veya tanımlayıcının mevcut ancak hiçbir saat dilimi verisi içermediği anlamına gelir.This means that a time zone identifier whose name matches id does not exist, or that the identifier exists but does not contain any time zone data.

İşlem, saat dilimi bilgilerini içeren kayıt defteri anahtarından okumak için gerekli izinlere sahip değildir.The process does not have the permissions required to read from the registry key that contains the time zone information.

Saat dilimi tanımlayıcısı bulundu, ancak kayıt defteri verileri bozuk.The time zone identifier was found, but the registry data is corrupted.

Örnekler

Aşağıdaki örnek, FindSystemTimeZoneById Tokyo standart saat dilimini almak için yöntemini kullanır.The following example uses the FindSystemTimeZoneById method to retrieve the Tokyo Standard Time zone. Bu TimeZoneInfo nesne daha sonra yerel saati Tokyo 'daki saate dönüştürmek ve Tokyo standart saati veya Tokyo yaz saati olup olmadığını anlamak için kullanılır.This TimeZoneInfo object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time.

using System;

public class Example
{
   public static void Main()
   {
      // Get time in local time zone 
      DateTime thisTime = DateTime.Now;
      Console.WriteLine("Time in {0} zone: {1}", TimeZoneInfo.Local.IsDaylightSavingTime(thisTime) ?
                        TimeZoneInfo.Local.DaylightName : TimeZoneInfo.Local.StandardName, thisTime);
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local));
      // Get Tokyo Standard Time zone
      TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
      DateTime tstTime = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst);      
      Console.WriteLine("Time in {0} zone: {1}", tst.IsDaylightSavingTime(tstTime) ?
                        tst.DaylightName : tst.StandardName, tstTime);
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst));
   }
}
// The example displays output like the following when run on a system in the
// U.S. Pacific Standard Time zone:
//       Time in Pacific Standard Time zone: 12/6/2013 10:57:51 AM
//          UTC Time: 12/6/2013 6:57:51 PM
//       Time in Tokyo Standard Time zone: 12/7/2013 3:57:51 AM
//          UTC Time: 12/6/2013 6:57:51 PM
Module Example
   Public Sub Main()
      ' Get time in local time zone 
      Dim thisTime As Date = Date.Now
      Console.WriteLine("Time in {0} zone: {1}", IIf(TimeZoneInfo.Local.IsDaylightSavingTime(thisTime), 
                        TimeZoneInfo.Local.DaylightName, TimeZoneInfo.Local.StandardName), thisTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local))
      ' Get Tokyo Standard Time zone
      Dim tst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")
      Dim tstTime As Date = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst)      
      Console.WriteLine("Time in {0} zone: {1}", IIf(tst.IsDaylightSavingTime(tstTime), 
                        tst.DaylightName, tst.StandardName), tstTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst))
   End Sub
End Module
' The example displays output like the following when run on a system in the U.S.
' Pacific Standard Time zone:
'    Time in Pacific Standard Time zone: 12/6/2013 10:57:51 AM
'       UTC Time: 12/6/2013 6:57:51 PM
'    Time in Tokyo Standard Time zone: 12/7/2013 3:57:51 AM
'       UTC Time: 12/6/2013 6:57:51 PM

Açıklamalar

idParametresi, başarılı bir eşleşmenin gerçekleşmesi için tam olarak saat diliminin tanımlayıcısına karşılık gelmelidir, ancak bu, id zaman dilimi tanımlayıcılarıyla karşılaştırma büyük/küçük harfe duyarsızdır.The id parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of id with time zone identifiers is case-insensitive. Kısmi eşleştirmelere göre saat dilimi nesnelerini almak isterseniz, yöntemi tarafından döndürülen salt okunurdur nesneler koleksiyonuyla çalışan özel yordamlar yazabilirsiniz TimeZoneInfo GetSystemTimeZones .If you want to retrieve time zone objects based on partial matches, you can write custom procedures that work with the read-only collection of TimeZoneInfo objects returned by the GetSystemTimeZones method.

Windows sistemlerinde, FindSystemTimeZoneById id kayıt defterinin HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones dalının alt anahtar adlarıyla eşleştirmeye çalışır.On Windows systems, FindSystemTimeZoneById tries to match id to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. Linux ve macOS 'ta, ICU kitaplığındabulunan saat dilimi bilgilerini kullanır.On Linux and macOS, it uses time zone information available in the ICU Library. Kayıt defteri veya kitaplıkta istediğiniz zaman dilimine ait bilgiler yoksa, yöntemin aşırı yüklemelerinin birini çağırarak CreateCustomTimeZone veya FromSerializedString TimeZoneInfo gerekli saat dilimini temsil eden bir nesneyi seri durumdan çıkarmak için çağırarak belirli bir saat dilimi oluşturabilirsiniz.If the registry or the library does not have the information for the time zone you desire, you can create a particular time zone either by calling one of the overloads of the CreateCustomTimeZone method or by calling FromSerializedString to deserialize a TimeZoneInfo object that represents the required time zone. Ancak, bu yöntem çağrıları tarafından oluşturulan saat dilimleri sistem tanımlı zaman değildir ve yöntemi kullanılarak alınamaz FindSystemTimeZoneById .However, time zones created by these method calls are not system-defined time and cannot be retrieved using the FindSystemTimeZoneById method. Bu özel saat dilimlerine yalnızca CreateCustomTimeZone veya yöntem çağrısı tarafından döndürülen nesne başvurusu aracılığıyla erişilebilir FromSerializedString .These custom time zones can be accessed only through the object reference returned by the CreateCustomTimeZone or FromSerializedString method call.

Bu yöntem TimeZoneInfo her yöntem çağrısı için yeni bir örnek döndürür; önbelleğe alınmış nesneleri döndürmez.This method returns a new TimeZoneInfo instance for each method call; it does not return cached objects. Bu, FindSystemTimeZoneById yöntemi aynı tanımlayıcıyla sürekli olarak çağıran uygulamalardaki performansı etkileyebilir.This may impact performance in applications that call the FindSystemTimeZoneById method repeatedly with the same identifier.

Şunlara uygulanır

Ayrıca bkz.