TimeZoneInfo.ConvertTime Metod

Definition

Konverterar en tid till tiden i en viss tidszon.

Överlagringar

Name Description
ConvertTime(DateTime, TimeZoneInfo)

Konverterar en tid till tiden i en viss tidszon.

ConvertTime(DateTimeOffset, TimeZoneInfo)

Konverterar en tid till tiden i en viss tidszon.

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

Konverterar en tid från en tidszon till en annan.

ConvertTime(DateTime, TimeZoneInfo)

Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs

Konverterar en tid till tiden i en viss tidszon.

public:
 static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo ^ destinationTimeZone);
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone);
static member ConvertTime : DateTime * TimeZoneInfo -> DateTime
Public Shared Function ConvertTime (dateTime As DateTime, destinationTimeZone As TimeZoneInfo) As DateTime

Parametrar

dateTime
DateTime

Datum och tid som ska konverteras.

destinationTimeZone
TimeZoneInfo

Tidszonen som ska konverteras dateTime till.

Returer

Datum och tid i måltidszonen.

Undantag

Värdet för parametern dateTime representerar en ogiltig tid.

Värdet för parametern destinationTimeZone är null.

Exempel

I följande exempel konverteras en matris med datum- och tidsvärden till tider i den östra tidszonen i USA och Kanada. Den visar att källtidszonen är beroende av källvärdets DateTime.KindDateTime egenskap. Det visar också att ConvertTime metoden tar hänsyn till tidszonsjusteringar eftersom en tidszonsjustering sker i både käll- och måltidszonerna klockan 02:00 den 7 november 2010.

using System;

public class Example
{
   public static void Main()
   {
      // Define times to be converted.
      DateTime[] times = { new DateTime(2010, 1, 1, 0, 1, 0), 
                           new DateTime(2010, 1, 1, 0, 1, 0, DateTimeKind.Utc), 
                           new DateTime(2010, 1, 1, 0, 1, 0, DateTimeKind.Local),                            
                           new DateTime(2010, 11, 6, 23, 30, 0),
                           new DateTime(2010, 11, 7, 2, 30, 0) };
                              
      // Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
      TimeZoneInfo est; 
      try {
         est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
      }
      catch (TimeZoneNotFoundException) {
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
         return;
      }
      catch (InvalidTimeZoneException) {
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
         return;
      }   

      // Display the current time zone name.
      Console.WriteLine("Local time zone: {0}\n", TimeZoneInfo.Local.DisplayName);
      
      // Convert each time in the array.
      foreach (DateTime timeToConvert in times)
      {
         DateTime targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est);
         Console.WriteLine("Converted {0} {1} to {2}.", timeToConvert, 
                           timeToConvert.Kind, targetTime);
      }                        
   }
}
// The example displays the following output:
//    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
//    
//    Converted 1/1/2010 12:01:00 AM Unspecified to 1/1/2010 3:01:00 AM.
//    Converted 1/1/2010 12:01:00 AM Utc to 12/31/2009 7:01:00 PM.
//    Converted 1/1/2010 12:01:00 AM Local to 1/1/2010 3:01:00 AM.
//    Converted 11/6/2010 11:30:00 PM Unspecified to 11/7/2010 1:30:00 AM.
//    Converted 11/7/2010 2:30:00 AM Unspecified to 11/7/2010 5:30:00 AM.
open System

// Define times to be converted.
let times = 
    [| DateTime(2010, 1, 1, 0, 1, 0)
       DateTime(2010, 1, 1, 0, 1, 0, DateTimeKind.Utc)
       DateTime(2010, 1, 1, 0, 1, 0, DateTimeKind.Local)
       DateTime(2010, 11, 6, 23, 30, 0)
       DateTime(2010, 11, 7, 2, 30, 0) |]
                        
// Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
try
    let est = TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"

    // Display the current time zone name.
    printfn $"Local time zone: {TimeZoneInfo.Local.DisplayName}\n"

    // Convert each time in the array.
    for timeToConvert in times do
        let targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est)
        printfn $"Converted {timeToConvert} {timeToConvert.Kind} to {targetTime}."
with
| :? TimeZoneNotFoundException ->
    printfn "Unable to retrieve the Eastern Standard time zone."
| :? InvalidTimeZoneException ->
    printfn "Unable to retrieve the Eastern Standard time zone."
// The example displays the following output:
//    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
//    
//    Converted 1/1/2010 12:01:00 AM Unspecified to 1/1/2010 3:01:00 AM.
//    Converted 1/1/2010 12:01:00 AM Utc to 12/31/2009 7:01:00 PM.
//    Converted 1/1/2010 12:01:00 AM Local to 1/1/2010 3:01:00 AM.
//    Converted 11/6/2010 11:30:00 PM Unspecified to 11/7/2010 1:30:00 AM.
//    Converted 11/7/2010 2:30:00 AM Unspecified to 11/7/2010 5:30:00 AM.
Module Example
   Public Sub Main()
      ' Define times to be converted.
      Dim times() As Date = { #1/1/2010 12:01AM#, _
                              DateTime.SpecifyKind(#1/1/2010 12:01AM#, DateTimeKind.Utc), _
                              DateTime.SpecifyKind(#1/1/2010 12:01AM#, DateTimeKind.Local), _
                              #11/6/2010 11:30PM#, #11/7/2010 2:30AM# }
                              
      ' Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
      Dim est As TimeZoneInfo 
      Try
         est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
      Catch e As TimeZoneNotFoundException
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.")
         Exit Sub
      Catch e As InvalidTimeZoneException
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.")
         Exit Sub
      End Try   

      ' Display the current time zone name.
      Console.WriteLine("Local time zone: {0}", TimeZoneInfo.Local.DisplayName)
      Console.WriteLine()
      
      ' Convert each time in the array.
      For Each timeToConvert As Date In times
         Dim targetTime As Date = TimeZoneInfo.ConvertTime(timeToConvert, est)
         Console.WriteLine("Converted {0} {1} to {2}.", timeToConvert, _
                           timeToConvert.Kind, targetTime)
      Next                        
   End Sub
End Module
' The example displays the following output:
'    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
'    
'    Converted 1/1/2010 12:01:00 AM Unspecified to 1/1/2010 3:01:00 AM.
'    Converted 1/1/2010 12:01:00 AM Utc to 12/31/2009 7:01:00 PM.
'    Converted 1/1/2010 12:01:00 AM Local to 1/1/2010 3:01:00 AM.
'    Converted 11/6/2010 11:30:00 PM Unspecified to 11/7/2010 1:30:00 AM.
'    Converted 11/7/2010 2:30:00 AM Unspecified to 11/7/2010 5:30:00 AM.

Kommentarer

När du utför konverteringen ConvertTime(DateTimeOffset, TimeZoneInfo) tillämpar metoden eventuella justeringsregler som gäller i tidszonen destinationTimeZone .

Den här överlagringen ConvertTime(DateTime, TimeZoneInfo) av metoden avgör källtidszonen från värdet för dateTime parameterns Kind egenskap, som följande tabell visar.

Typegenskapsvärde Källtidszon Metodbeteende
DateTimeKind.Local Local Konverterar den lokala tiden till tiden i destinationTimeZone.
DateTimeKind.Utc Utc Konverterar UTC (Coordinated Universal Time) till tiden i destinationTimeZone.
DateTimeKind.Unspecified Antas vara Local. Konverterar den lokala tiden till tiden i destinationTimeZone.

Egenskapen Kind för det returnerade DateTime värdet anges enligt följande tabell.

Tillstånd Returnerat egenskapsvärde för Typ
destinationTimeZone är TimeZoneInfo.Utc. DateTimeKind.Utc
destinationTimeZone är TimeZoneInfo.Local. DateTimeKind.Local
Alla andra datum- och tidsvärden och måltidszoner. DateTimeKind.Unspecified

Om värdet för parametern dateTime är en tvetydig lokal tid tolkas det som en standardtid. Om parametern dateTime är en ogiltig lokal tid genererar den här metoden en ArgumentException.

Om konverteringen av dateTime resulterar i ett datum- och tidsvärde som är tidigare än DateTime.MinValue eller senare än DateTime.MaxValuereturnerar DateTime.MinValue den här metoden respektive DateTime.MaxValue.

Du kan också konvertera till eller från UTC genom att anropa ConvertTimeFromUtc metoderna och ConvertTimeToUtc .

Se även

Gäller för

ConvertTime(DateTimeOffset, TimeZoneInfo)

Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs

Konverterar en tid till tiden i en viss tidszon.

public:
 static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo ^ destinationTimeZone);
public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone);
static member ConvertTime : DateTimeOffset * TimeZoneInfo -> DateTimeOffset
Public Shared Function ConvertTime (dateTimeOffset As DateTimeOffset, destinationTimeZone As TimeZoneInfo) As DateTimeOffset

Parametrar

dateTimeOffset
DateTimeOffset

Datum och tid som ska konverteras.

destinationTimeZone
TimeZoneInfo

Tidszonen som ska konverteras dateTimeOffset till.

Returer

Datum och tid i måltidszonen.

Undantag

Värdet för parametern destinationTimeZone är null.

Exempel

I följande exempel konverteras en matris med DateTimeOffset värden till tider i den östra tidszonen i USA och Kanada. Det visar att ConvertTime metoden tar hänsyn till tidszonsjusteringar eftersom en tidszonsjustering sker i både käll- och måltidszonerna kl. 02:00 den 7 november 2010.

using System;

public class Example
{
   public static void Main()
   {
      // Define times to be converted.
      DateTime time1 = new DateTime(2010, 1, 1, 12, 1, 0);
      DateTime time2 = new DateTime(2010, 11, 6, 23, 30, 0);
      DateTimeOffset[] times = { new DateTimeOffset(time1, TimeZoneInfo.Local.GetUtcOffset(time1)),
                                 new DateTimeOffset(time1, TimeSpan.Zero),
                                 new DateTimeOffset(time2, TimeZoneInfo.Local.GetUtcOffset(time2)),
                                 new DateTimeOffset(time2.AddHours(3), TimeZoneInfo.Local.GetUtcOffset(time2.AddHours(3))) };
                              
      // Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
      TimeZoneInfo est; 
      try {
         est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
      }
      catch (TimeZoneNotFoundException) {
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
         return;
      }
      catch (InvalidTimeZoneException) {
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
         return;
      }   

      // Display the current time zone name.
      Console.WriteLine("Local time zone: {0}\n", TimeZoneInfo.Local.DisplayName);
      
      // Convert each time in the array.
      foreach (DateTimeOffset timeToConvert in times)
      {
         DateTimeOffset targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est);
         Console.WriteLine("Converted {0} to {1}.", timeToConvert, targetTime);
      }                        
   }
}
// The example displays the following output:
//    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
//    
//    Converted 1/1/2010 12:01:00 AM -08:00 to 1/1/2010 3:01:00 AM -05:00.
//    Converted 1/1/2010 12:01:00 AM +00:00 to 12/31/2009 7:01:00 PM -05:00.
//    Converted 11/6/2010 11:30:00 PM -07:00 to 11/7/2010 1:30:00 AM -05:00.
//    Converted 11/7/2010 2:30:00 AM -08:00 to 11/7/2010 5:30:00 AM -05:00.
open System

// Define times to be converted.
let time1 = DateTime(2010, 1, 1, 12, 1, 0)
let time2 = DateTime(2010, 11, 6, 23, 30, 0)
let times = 
    [| DateTimeOffset(time1, TimeZoneInfo.Local.GetUtcOffset time1)
       DateTimeOffset(time1, TimeSpan.Zero)
       DateTimeOffset(time2, TimeZoneInfo.Local.GetUtcOffset time2)
       DateTimeOffset(time2.AddHours 3, TimeZoneInfo.Local.GetUtcOffset(time2.AddHours 3)) |]
                        
// Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
try
    let est = TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time"

    // Display the current time zone name.
    printfn $"Local time zone: {TimeZoneInfo.Local.DisplayName}\n"

    // Convert each time in the array.
    for timeToConvert in times do
        let targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est)
        printfn $"Converted {timeToConvert} to {targetTime}."
with
| :? TimeZoneNotFoundException ->
    printfn "Unable to retrieve the Eastern Standard time zone."
| :? InvalidTimeZoneException ->
    printfn "Unable to retrieve the Eastern Standard time zone."
// The example displays the following output:
//    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
//    
//    Converted 1/1/2010 12:01:00 AM -08:00 to 1/1/2010 3:01:00 AM -05:00.
//    Converted 1/1/2010 12:01:00 AM +00:00 to 12/31/2009 7:01:00 PM -05:00.
//    Converted 11/6/2010 11:30:00 PM -07:00 to 11/7/2010 1:30:00 AM -05:00.
//    Converted 11/7/2010 2:30:00 AM -08:00 to 11/7/2010 5:30:00 AM -05:00.
Module Example
   Public Sub Main()
      ' Define times to be converted.
      Dim time1 As Date = #1/1/2010 12:01AM#
      Dim time2 As Date = #11/6/2010 11:30PM#
      Dim times() As DateTimeOffset = { New DateTimeOffset(time1, TimeZoneInfo.Local.GetUtcOffset(time1)), _
                                        New DateTimeOffset(time1, Timespan.Zero), _
                                        New DateTimeOffset(time2, TimeZoneInfo.Local.GetUtcOffset(time2)), _
                                        New DateTimeOffset(time2.AddHours(3), TimeZoneInfo.Local.GetUtcOffset(time2.AddHours(3))) }
                              
      ' Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
      Dim est As TimeZoneInfo 
      Try
         est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")
      Catch e As TimeZoneNotFoundException
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.")
         Exit Sub
      Catch e As InvalidTimeZoneException
         Console.WriteLine("Unable to retrieve the Eastern Standard time zone.")
         Exit Sub
      End Try   

      ' Display the current time zone name.
      Console.WriteLine("Local time zone: {0}", TimeZoneInfo.Local.DisplayName)
      Console.WriteLine()
      
      ' Convert each time in the array.
      For Each timeToConvert As DateTimeOffset In times
         Dim targetTime As DateTimeOffset = TimeZoneInfo.ConvertTime(timeToConvert, est)
         Console.WriteLine("Converted {0} to {1}.", timeToConvert, targetTime)
      Next                        
   End Sub
End Module
' The example displays the following output:
'    Local time zone: (GMT-08:00) Pacific Time (US & Canada)
'    
'    Converted 1/1/2010 12:01:00 AM -08:00 to 1/1/2010 3:01:00 AM -05:00.
'    Converted 1/1/2010 12:01:00 AM +00:00 to 12/31/2009 7:01:00 PM -05:00.
'    Converted 11/6/2010 11:30:00 PM -07:00 to 11/7/2010 1:30:00 AM -05:00.
'    Converted 11/7/2010 2:30:00 AM -08:00 to 11/7/2010 5:30:00 AM -05:00.

Kommentarer

När du utför konverteringen ConvertTime(DateTimeOffset, TimeZoneInfo) tillämpar metoden eventuella justeringsregler som gäller i tidszonen destinationTimeZone .

Den här överlagringen skiljer sig från de andra överlagringarna av ConvertTime metoden genom att acceptera ett DateTimeOffset värde som den första parametern. Detta identifierar datum och tid som en förskjutning från Coordinated Universal Time (UTC) i stället för som datum och tid i en viss tidszon. Därför kan parametern dateTimeOffset inte representera en tvetydig tid eller en ogiltig tid.

När du konverterar dateTimeOffset värdet till tiden i måltidszonen tar den här metoden hänsyn till eventuella justeringsregler som gäller i måltidszonen.

Om konverteringen av dateTimeOffset resulterar i ett datum- och tidsvärde som är tidigare än DateTimeOffset.MinValue eller senare än DateTimeOffset.MaxValuereturnerar DateTimeOffset.MinValue den här metoden respektive DateTimeOffset.MaxValue.

Se även

Gäller för

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs
Källa:
TimeZoneInfo.cs

Konverterar en tid från en tidszon till en annan.

public:
 static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo ^ sourceTimeZone, TimeZoneInfo ^ destinationTimeZone);
public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone);
static member ConvertTime : DateTime * TimeZoneInfo * TimeZoneInfo -> DateTime
Public Shared Function ConvertTime (dateTime As DateTime, sourceTimeZone As TimeZoneInfo, destinationTimeZone As TimeZoneInfo) As DateTime

Parametrar

dateTime
DateTime

Datum och tid som ska konverteras.

sourceTimeZone
TimeZoneInfo

Tidszonen dateTimeför .

destinationTimeZone
TimeZoneInfo

Tidszonen som ska konverteras dateTime till.

Returer

Datum och tid i måltidszonen som motsvarar parametern dateTime i källtidszonen.

Undantag

Egenskapen Kind för parametern dateTime är Local, men parametern sourceTimeZone är inte lika med Local.

-eller-

Egenskapen Kind för parametern dateTime är Utc, men parametern sourceTimeZone är inte lika med Utc.

-eller-

Parametern dateTime är en ogiltig tid (den representerar en tid som inte finns på grund av tidszonens justeringsregler).

Parametern sourceTimeZone är null.

-eller-

Parametern destinationTimeZone är null.

Exempel

I följande exempel visas hur metoden används ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) för att konvertera från Hawaiian Standard Time till lokal tid.

DateTime hwTime = new DateTime(2007, 02, 01, 08, 00, 00);
try
{
   TimeZoneInfo hwZone = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");
   Console.WriteLine("{0} {1} is {2} local time.", 
           hwTime, 
           hwZone.IsDaylightSavingTime(hwTime) ? hwZone.DaylightName : hwZone.StandardName, 
           TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local));
}
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The registry does not define the Hawaiian Standard Time zone.");
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Registry data on the Hawaiian Standard Time zone has been corrupted.");
}
let hwTime = DateTime(2007, 02, 01, 08, 00, 00)
try
    let hwZone = TimeZoneInfo.FindSystemTimeZoneById "Hawaiian Standard Time"
    printfn $"{hwTime} {if hwZone.IsDaylightSavingTime hwTime then hwZone.DaylightName else hwZone.StandardName} is {TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local)} local time." 
with
| :? TimeZoneNotFoundException ->
    printfn "The registry does not define the Hawaiian Standard Time zone."
| :? InvalidTimeZoneException ->
    printfn "Registry data on the Hawaiian Standard Time zone has been corrupted."
Dim hwTime As Date = #2/01/2007 8:00:00 AM#
Try
   Dim hwZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time")
   Console.WriteLine("{0} {1} is {2} local time.", _
                     hwTime, _
                     IIf(hwZone.IsDaylightSavingTime(hwTime), hwZone.DaylightName, hwZone.StandardName), _
                     TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local))
Catch e As TimeZoneNotFoundException
   Console.WriteLine("The registry does not define the Hawaiian Standard Time zone.")
Catch e As InvalidTimeZoneException
   Console.WriteLine("Registry data on the Hawaiian Standard Time zone has been corrupted.")
End Try

Kommentarer

När du utför konverteringen ConvertTime tillämpar metoden eventuella justeringsregler som gäller i tidszonen destinationTimeZone .

Värdet för egenskapen för Kind parametern dateTime måste motsvara parametern sourceTimeZone , som följande tabell visar.

DateTime.Kind-värde sourceTimeZone-värde Metodbeteende
DateTimeKind.Utc Är lika med TimeZoneInfo.Utc. Konverterar dateTime till måltidszonens tid.
DateTimeKind.Utc Är inte lika med TimeZoneInfo.Utc. Kastar en ArgumentException.
DateTimeKind.Local Är lika med TimeZoneInfo.Local. Konverterar dateTime till måltidszonens tid.
DateTimeKind.Local Är inte lika med TimeZoneInfo.Local. Kastar en ArgumentException.
DateTimeKind.Unspecified Någon. Konverterar dateTime till måltidszonens tid.

Du kan också konvertera till eller från Coordinated Universal Time (UTC) genom att anropa ConvertTimeFromUtc metoderna och ConvertTimeToUtc .

Egenskapen Kind för det returnerade DateTime värdet anges enligt följande tabell.

Tillstånd Returnerat egenskapsvärde för Typ
Argumentet destinationTimeZone är TimeZoneInfo.Utc. DateTimeKind.Utc
Argumentet destinationTimeZone är TimeZoneInfo.Local. DateTimeKind.Local
Alla andra datum- och tidsvärden, källtidszoner och måltidszoner. DateTimeKind.Unspecified

Om värdet för parametern dateTime är en tvetydig tid i källtidszonen tolkas det som en standardtid. Om parametern dateTime är en ogiltig tid i källtidszonen genererar den här metoden en ArgumentException.

Om konverteringen av dateTime resulterar i ett datum- och tidsvärde som är tidigare än DateTime.MinValue eller senare än DateTime.MaxValuereturnerar DateTime.MinValue den här metoden respektive DateTime.MaxValue.

Metoden ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) utlöser ett ArgumentException undantag om DateTime.Kind egenskapen för dateTime argumentet är DateTimeKind.Local men sourceTimeZone argumentet inte TimeZoneInfo.Localär . För att avgöra om källtidszonen är den lokala tidszonen eller den universella tidszonen testar metoden för referensjämlikhet i stället för att testa för värdejämlikhet med Equals(TimeZoneInfo) metoden. Observera att TimeZoneInfo objekt som representerar den lokala tidszonen och som hämtas genom att anropa FindSystemTimeZoneById metoden inte har referensjämlikhet med TimeZoneInfo.Local. Dessutom TimeZoneInfo har objekt som representerar den lokala eller universella tidszonen och som hämtas genom iterering av samlingen som returneras av GetSystemTimeZones metoden inte referensjämlikhet med TimeZoneInfo.Local eller TimeZoneInfo.Utc. Alternativt kan du anropa ConvertTimeBySystemTimeZoneId(DateTime, String, String) metoden.

Se även

Gäller för