TimeZoneInfo.ConvertTime 方法

定义

将时间转换为特定时区的时间。Converts a time to the time in a particular time zone.

重载

ConvertTime(DateTime, TimeZoneInfo)

将时间转换为特定时区的时间。Converts a time to the time in a particular time zone.

ConvertTime(DateTimeOffset, TimeZoneInfo)

将时间转换为特定时区的时间。Converts a time to the time in a particular time zone.

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

将时间从一个时区转换到另一个时区。Converts a time from one time zone to another.

ConvertTime(DateTime, TimeZoneInfo)

将时间转换为特定时区的时间。Converts a time to the time in a particular time zone.

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

参数

dateTime
DateTime

要转换的日期和时间。The date and time to convert.

destinationTimeZone
TimeZoneInfo

要将 dateTime 转换到的时区。The time zone to convert dateTime to.

返回

DateTime

目标时区的日期和时间。The date and time in the destination time zone.

例外

dateTime 参数值表示无效的时间。The value of the dateTime parameter represents an invalid time.

destinationTimeZone 参数的值为 nullThe value of the destinationTimeZone parameter is null.

示例

下面的示例将日期和时间值的数组转换为美国和加拿大东部时区的时间。The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. 它显示源时区依赖于 DateTime.Kind 源值的属性 DateTimeIt shows that the source time zone depends on the DateTime.Kind property of the source DateTime value. 它还说明了 ConvertTime 方法会考虑时区调整,因为时区调整会在上午2:00 的源时区和目标时区进行调整。It also illustrates that the ConvertTime method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. 2010年11月7日。on November 7, 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.
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.

注解

执行转换时,方法会 ConvertTime(DateTimeOffset, TimeZoneInfo) 应用时区中有效的任何调整规则 destinationTimeZoneWhen performing the conversion, the ConvertTime(DateTimeOffset, TimeZoneInfo) method applies any adjustment rules in effect in the destinationTimeZone time zone.

此方法的重载根据 ConvertTime(DateTime, TimeZoneInfo) 参数的属性的值确定源时区,如下 dateTime Kind 表所示。This overload of the ConvertTime(DateTime, TimeZoneInfo) method determines the source time zone from the value of the dateTime parameter's Kind property, as the following table shows.

Kind 属性值Kind property value 源时区Source time zone 方法行为Method behavior
DateTimeKind.Local Local 将本地时间转换为中的时间 destinationTimeZoneConverts the local time to the time in destinationTimeZone.
DateTimeKind.Utc Utc 将协调世界时 (UTC) 转换为中的时间 destinationTimeZoneConverts Coordinated Universal Time (UTC) to the time in destinationTimeZone.
DateTimeKind.Unspecified 假定为 LocalAssumed to be Local. 将本地时间转换为中的时间 destinationTimeZoneConverts the local time to the time in destinationTimeZone.

Kind返回的值的属性的设置如下 DateTime 表所示。The Kind property of the returned DateTime value is set as shown in the following table.

条件Condition 返回的 Kind 属性值Returned Kind property value
destinationTimeZoneTimeZoneInfo.UtcThe destinationTimeZone is TimeZoneInfo.Utc. DateTimeKind.Utc
destinationTimeZoneTimeZoneInfo.LocalThe destinationTimeZone is TimeZoneInfo.Local. DateTimeKind.Local
所有其他日期和时间值以及目标时区。All other date and time values and destination time zones. DateTimeKind.Unspecified

如果参数的值 dateTime 是不明确的本地时间,则将其解释为标准时间。If the value of the dateTime parameter is an ambiguous local time, it is interpreted as a standard time. 如果 dateTime 参数是无效的本地时间,则此方法将引发 ArgumentExceptionIf the dateTime parameter is an invalid local time, this method throws an ArgumentException.

如果的转换 dateTime 结果的日期和时间值早于 DateTime.MinValue 或晚于 DateTime.MaxValue ,则此方法将 DateTime.MinValue 分别返回或 DateTime.MaxValueIf the conversion of dateTime results in a date and time value that is earlier than DateTime.MinValue or later than DateTime.MaxValue, this method returns DateTime.MinValue or DateTime.MaxValue, respectively.

还可以通过调用和方法转换为 UTC 或从 UTC 转换 ConvertTimeFromUtc ConvertTimeToUtcYou can also convert to or from UTC by calling the ConvertTimeFromUtc and ConvertTimeToUtc methods.

适用于

ConvertTime(DateTimeOffset, TimeZoneInfo)

将时间转换为特定时区的时间。Converts a time to the time in a particular time zone.

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

参数

dateTimeOffset
DateTimeOffset

要转换的日期和时间。The date and time to convert.

destinationTimeZone
TimeZoneInfo

要将 dateTime 转换到的时区。The time zone to convert dateTime to.

返回

DateTimeOffset

目标时区的日期和时间。The date and time in the destination time zone.

例外

destinationTimeZone 参数的值为 nullThe value of the destinationTimeZone parameter is null.

示例

下面的示例将值数组转换 DateTimeOffset 为美国和加拿大东部时区的时间。The following example converts an array of DateTimeOffset values to times in the Eastern Time zone of the U.S. and Canada. 它阐释了 ConvertTime 方法会考虑时区调整,因为在凌晨2:00 的源时区和目标时区都发生了时区调整。It illustrates that the ConvertTime method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. 2010年11月7日。on November 7, 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.
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.

注解

执行转换时,方法会 ConvertTime(DateTimeOffset, TimeZoneInfo) 应用时区中有效的任何调整规则 destinationTimeZoneWhen performing the conversion, the ConvertTime(DateTimeOffset, TimeZoneInfo) method applies any adjustment rules in effect in the destinationTimeZone time zone.

此重载不同于方法的其他重载, ConvertTime 方法是接受 DateTimeOffset 值作为其第一个参数。This overload differs from the other overloads of the ConvertTime method by accepting a DateTimeOffset value as its first parameter. 这会将日期和时间标识为协调世界时 (UTC) 而不是特定时区中的日期和时间的偏移量。This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. 因此,该 dateTimeOffset 参数不能表示不明确的时间或无效的时间。As a result, the dateTimeOffset parameter cannot represent either an ambiguous time or an invalid time.

在将 dateTimeOffset 值转换为目标时区中的时间时,此方法会考虑目标时区中任何有效的调整规则。In converting the dateTimeOffset value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone.

如果的转换 dateTimeOffset 结果的日期和时间值早于 DateTimeOffset.MinValue 或晚于 DateTimeOffset.MaxValue ,则此方法将 DateTimeOffset.MinValue 分别返回或 DateTimeOffset.MaxValueIf the conversion of dateTimeOffset results in a date and time value that is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue, this method returns DateTimeOffset.MinValue or DateTimeOffset.MaxValue, respectively.

适用于

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

将时间从一个时区转换到另一个时区。Converts a time from one time zone to another.

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

参数

dateTime
DateTime

要转换的日期和时间。The date and time to convert.

sourceTimeZone
TimeZoneInfo

dateTime 的时区。The time zone of dateTime.

destinationTimeZone
TimeZoneInfo

要将 dateTime 转换到的时区。The time zone to convert dateTime to.

返回

DateTime

目标时区中与源时区中的 dateTime 参数对应的日期和时间。The date and time in the destination time zone that corresponds to the dateTime parameter in the source time zone.

例外

dateTime 参数的 Kind 属性是 Local,但 sourceTimeZone 参数不等于 LocalThe Kind property of the dateTime parameter is Local, but the sourceTimeZone parameter does not equal Local.

- 或 --or- dateTime 参数的 Kind 属性是 Utc,但 sourceTimeZone 参数不等于 UtcThe Kind property of the dateTime parameter is Utc, but the sourceTimeZone parameter does not equal Utc.

- 或 --or- dateTime 参数是无效时间(即,由于时区的调整规则,它表示不存在的时间)。The dateTime parameter is an invalid time (that is, it represents a time that does not exist because of a time zone's adjustment rules).

sourceTimeZone 参数为 nullThe sourceTimeZone parameter is null.

- 或 --or- destinationTimeZone 参数为 nullThe destinationTimeZone parameter is null.

示例

下面的示例演示如何使用方法将 ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) 夏威夷标准时间转换为本地时间。The following example illustrates the use of the ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) method to convert from Hawaiian Standard Time to local time.

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.");
}
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                     

注解

执行转换时,方法会 ConvertTime 应用时区中有效的任何调整规则 destinationTimeZoneWhen performing the conversion, the ConvertTime method applies any adjustment rules in effect in the destinationTimeZone time zone.

参数的属性值 Kind dateTime 必须对应于 sourceTimeZone 参数,如下表所示。The value of the Kind property of the dateTime parameter must correspond to the sourceTimeZone parameter, as the following table shows.

DateTime 值DateTime.Kind value sourceTimeZone 值sourceTimeZone value 方法行为Method behavior
DateTimeKind.Utc 等于 TimeZoneInfo.UtcEquals TimeZoneInfo.Utc. 转换 dateTime 为目标时区的时间。Converts dateTime to the destination time zone's time.
DateTimeKind.Utc Does not equal TimeZoneInfo.UtcDoes not equal TimeZoneInfo.Utc. 引发 ArgumentExceptionThrows an ArgumentException.
DateTimeKind.Local 等于 TimeZoneInfo.LocalEquals TimeZoneInfo.Local. 转换 dateTime 为目标时区的时间。Converts dateTime to the destination time zone's time.
DateTimeKind.Local Does not equal TimeZoneInfo.LocalDoes not equal TimeZoneInfo.Local. 引发 ArgumentExceptionThrows an ArgumentException.
DateTimeKind.Unspecified 随时.Any. 转换 dateTime 为目标时区的时间。Converts dateTime to the destination time zone's time.

还可以通过调用和方法,在协调世界时 (UTC) 转换为 ConvertTimeFromUtcConvertTimeToUtcYou can also convert to or from Coordinated Universal Time (UTC) by calling the ConvertTimeFromUtc and ConvertTimeToUtc methods.

Kind返回的值的属性的设置如下 DateTime 表所示。The Kind property of the returned DateTime value is set as shown in the following table.

条件Condition 返回的 Kind 属性值Returned Kind property value
destinationTimeZone 参数为 TimeZoneInfo.UtcThe destinationTimeZone argument is TimeZoneInfo.Utc. DateTimeKind.Utc
destinationTimeZone 参数为 TimeZoneInfo.LocalThe destinationTimeZone argument is TimeZoneInfo.Local. DateTimeKind.Local
所有其他日期和时间值、源时区和目标时区。All other date and time values, source time zones, and destination time zones. DateTimeKind.Unspecified

如果参数的值 dateTime 是源时区中不明确的时间,则将其解释为标准时间。If the value of the dateTime parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. 如果 dateTime 参数是源时区中的无效时间,则此方法将引发 ArgumentExceptionIf the dateTime parameter is an invalid time in the source time zone, this method throws an ArgumentException.

如果的转换 dateTime 结果的日期和时间值早于 DateTime.MinValue 或晚于 DateTime.MaxValue ,则此方法将 DateTime.MinValue 分别返回或 DateTime.MaxValueIf the conversion of dateTime results in a date and time value that is earlier than DateTime.MinValue or later than DateTime.MaxValue, this method returns DateTime.MinValue or DateTime.MaxValue, respectively.

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) ArgumentException 如果 DateTime.Kind 参数的属性 dateTime 为, DateTimeKind.Local 但该 sourceTimeZone 参数不 TimeZoneInfo.Local 是,则该方法将引发异常。The ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) method throws an ArgumentException exception if the DateTime.Kind property of the dateTime argument is DateTimeKind.Local but the sourceTimeZone argument is not TimeZoneInfo.Local. 若要确定源时区是本地时区还是通用时区,该方法将测试引用相等性,而不是测试与方法的值相等性 Equals(TimeZoneInfo)To determine whether the source time zone is the local time zone or the universal time zone, the method tests for reference equality instead of testing for value equality with the Equals(TimeZoneInfo) method. 请注意, TimeZoneInfo 表示本地时区的对象和通过调用方法检索到的对象没有 FindSystemTimeZoneById 与的引用相等性 TimeZoneInfo.LocalNote that TimeZoneInfo objects that represent the local time zone and that are retrieved by calling the FindSystemTimeZoneById method do not have referential equality with TimeZoneInfo.Local. 此外, TimeZoneInfo 通过循环访问由方法返回的集合来检索的对象 GetSystemTimeZones 不具有或的引用相等性 TimeZoneInfo.Local TimeZoneInfo.UtcFurthermore, TimeZoneInfo objects that represent the local or universal time zone and that are retrieved by iterating the collection returned by the GetSystemTimeZones method do not have referential equality with TimeZoneInfo.Local or TimeZoneInfo.Utc. 作为替代方法,可以调用 ConvertTimeBySystemTimeZoneId(DateTime, String, String) 方法。As an alternative, you can call the ConvertTimeBySystemTimeZoneId(DateTime, String, String) method.

另请参阅

适用于