TimeZoneInfo.ConvertTimeToUtc TimeZoneInfo.ConvertTimeToUtc TimeZoneInfo.ConvertTimeToUtc Method

정의

날짜 및 시간을 UTC(협정 세계시)로 변환합니다.Converts a date and time to Coordinated Universal Time (UTC).

오버로드

ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo)

지정된 표준 시간대의 시간을 UTC(협정 세계시)로 변환합니다.Converts the time in a specified time zone to Coordinated Universal Time (UTC).

ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime)

지정된 날짜 및 시간을 UTC(협정 세계시)로 변환합니다.Converts the specified date and time to Coordinated Universal Time (UTC).

ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo)

지정된 표준 시간대의 시간을 UTC(협정 세계시)로 변환합니다.Converts the time in a specified time zone to Coordinated Universal Time (UTC).

public:
 static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo ^ sourceTimeZone);
public static DateTime ConvertTimeToUtc (DateTime dateTime, TimeZoneInfo sourceTimeZone);
static member ConvertTimeToUtc : DateTime * TimeZoneInfo -> DateTime

매개 변수

dateTime
DateTime DateTime DateTime

변환할 날짜 및 시간입니다.The date and time to convert.

sourceTimeZone
TimeZoneInfo TimeZoneInfo TimeZoneInfo

dateTime의 표준 시간대입니다.The time zone of dateTime.

반환

dateTime 매개 변수에 해당하는 UTC(협정 세계시)입니다.The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. DateTime 개체의 Kind 속성은 항상 Utc로 설정됩니다.The DateTime object's Kind property is always set to Utc.

예외

dateTime.KinddateTime.Kind UtcsourceTimeZoneUtc과 다른 경우is Utc and sourceTimeZone does not equal Utc.

또는-or- dateTime.KinddateTime.Kind LocalsourceTimeZoneLocal과 다른 경우is Local and sourceTimeZone does not equal Local.

또는-or- sourceTimeZone.IsInvalidDateTime(dateTime)에서 true를 반환하는 경우sourceTimeZone.IsInvalidDateTime(dateTime) returns true.

sourceTimeZonenull인 경우sourceTimeZone is null.

예제

다음 예제에서는 로컬 시스템에서 현재 날짜를 검색 및를 Utc (협정 세계시)를 변환 합니다 도쿄 표준 시간을 변환 합니다 고 마지막으로 도쿄 표준 시간에서 UTC로 다시 변환 합니다.The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. 참고는 두 개의 UTC 시간이 동일 합니다.Note that the two UTC times are identical.

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

설명

경우는 Kind 의 속성을 dateTime 매개 변수가 같으면 DateTimeKind.UtcsourceTimeZone 매개 변수가 같으면 TimeZoneInfo.Utc,이 메서드가 반환 dateTime 모든 변환을 수행 하지 않고.If the Kind property of the dateTime parameter equals DateTimeKind.Utc and the sourceTimeZone parameter equals TimeZoneInfo.Utc, this method returns dateTime without performing any conversion.

경우 dateTime 해당 모호한 시간을이 메서드는 원본 표준 시간대의 표준 시간 임을 가정 합니다.If dateTime corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. 하는 경우 dateTime throw이이 메서드는 잘못 된 시간에 해당는 ArgumentException합니다.If dateTime corresponds to an invalid time, this method throws an ArgumentException.

경우에 해당 협정 세계시 (UTC) dateTime 이전의 DateTime.MinValue 이상는 DateTime.MaxValue,이 메서드가 반환 MinValue 또는 MaxValue각각.If the Coordinated Universal Time (UTC) equivalent of dateTime is earlier than DateTime.MinValue or later that DateTime.MaxValue, this method returns MinValue or MaxValue, respectively.

추가 정보

ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime)

지정된 날짜 및 시간을 UTC(협정 세계시)로 변환합니다.Converts the specified date and time to Coordinated Universal Time (UTC).

public:
 static DateTime ConvertTimeToUtc(DateTime dateTime);
public static DateTime ConvertTimeToUtc (DateTime dateTime);
static member ConvertTimeToUtc : DateTime -> DateTime

매개 변수

dateTime
DateTime DateTime DateTime

변환할 날짜 및 시간입니다.The date and time to convert.

반환

dateTime 매개 변수에 해당하는 UTC(협정 세계시)입니다.The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. DateTime 값의 Kind 속성은 항상 Utc로 설정됩니다.The DateTime value's Kind property is always set to Utc.

예외

TimeZoneInfo.Local.IsInvalidDateTime( dateTime )true를 반환합니다.TimeZoneInfo.Local.IsInvalidDateTime( dateTime ) returns true.

예제

다음 예제를 변환 하는 시간 값을 갖는 Kind 속성은 DateTimeKind.Utc, DateTimeKind.Local, 및 DateTimeKind.Unspecified각각.The following example illustrates the conversion of time values whose Kind property is DateTimeKind.Utc, DateTimeKind.Local, and DateTimeKind.Unspecified, respectively. 또한 변환이 모호 하 고 잘못 된 횟수를 보여 줍니다.It also illustrates the conversion of ambiguous and invalid times.

DateTime datNowLocal = DateTime.Now;
Console.WriteLine("Converting {0}, Kind {1}:", datNowLocal, datNowLocal.Kind);
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowLocal), TimeZoneInfo.ConvertTimeToUtc(datNowLocal).Kind);
Console.WriteLine();

DateTime datNowUtc = DateTime.UtcNow;
Console.WriteLine("Converting {0}, Kind {1}", datNowUtc, datNowUtc.Kind);
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowUtc), TimeZoneInfo.ConvertTimeToUtc(datNowUtc).Kind);
Console.WriteLine();

DateTime datNow = new DateTime(2007, 10, 26, 13, 32, 00);
Console.WriteLine("Converting {0}, Kind {1}", datNow, datNow.Kind);
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNow), TimeZoneInfo.ConvertTimeToUtc(datNow).Kind);
Console.WriteLine();

DateTime datAmbiguous = new DateTime(2007, 11, 4, 1, 30, 00);    
Console.WriteLine("Converting {0}, Kind {1}, Ambiguous {2}", datAmbiguous, datAmbiguous.Kind, TimeZoneInfo.Local.IsAmbiguousTime(datAmbiguous));
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datAmbiguous), TimeZoneInfo.ConvertTimeToUtc(datAmbiguous).Kind);
Console.WriteLine();

DateTime datInvalid = new DateTime(2007, 3, 11, 02, 30, 00);    
Console.WriteLine("Converting {0}, Kind {1}, Invalid {2}", datInvalid, datInvalid.Kind, TimeZoneInfo.Local.IsInvalidTime(datInvalid));
try
{
   Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datInvalid), TimeZoneInfo.ConvertTimeToUtc(datInvalid).Kind);
}
catch (ArgumentException e)
{   
   Console.WriteLine("   {0}: Cannot convert {1} to UTC.", e.GetType().Name, datInvalid);
}
Console.WriteLine();

DateTime datNearMax = new DateTime(9999, 12, 31, 22, 00, 00);
Console.WriteLine("Converting {0}, Kind {1}", datNearMax, datNearMax.Kind);
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNearMax), TimeZoneInfo.ConvertTimeToUtc(datNearMax).Kind);
Console.WriteLine();
//
// This example produces the following output if the local time zone 
// is Pacific Standard Time:
//
//    Converting 8/31/2007 2:26:28 PM, Kind Local:
//       ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
//    
//    Converting 8/31/2007 9:26:28 PM, Kind Utc
//       ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
//    
//    Converting 10/26/2007 1:32:00 PM, Kind Unspecified
//       ConvertTimeToUtc: 10/26/2007 8:32:00 PM, Kind Utc
//    
//    Converting 11/4/2007 1:30:00 AM, Kind Unspecified, Ambiguous True
//       ConvertTimeToUtc: 11/4/2007 9:30:00 AM, Kind Utc
//    
//    Converting 3/11/2007 2:30:00 AM, Kind Unspecified, Invalid True
//       ArgumentException: Cannot convert 3/11/2007 2:30:00 AM to UTC.
//    
//    Converting 12/31/9999 10:00:00 PM, Kind Unspecified
//       ConvertTimeToUtc: 12/31/9999 11:59:59 PM, Kind Utc
// 
Dim datNowLocal As Date = Date.Now
Console.WriteLine("Converting {0}, Kind {1}:", datNowLocal, datNowLocal.Kind)
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowLocal), TimeZoneInfo.ConvertTimeToUtc(datNowLocal).Kind)
Console.WriteLine()

Dim datNowUtc As Date = Date.UtcNow
Console.WriteLine("Converting {0}, Kind {1}", datNowUtc, datNowUtc.Kind)
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowUtc), TimeZoneInfo.ConvertTimeToUtc(datNowUtc).Kind)
Console.WriteLine()

Dim datNow As Date = CDate("10/26/2007 1:32:00 PM")
Console.WriteLine("Converting {0}, Kind {1}", datNow, datNow.Kind)
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNow), TimeZoneInfo.ConvertTimeToUtc(datNow).Kind)
Console.WriteLine()

Dim datAmbiguous As Date = #11/4/2007 1:30:00AM#    
Console.WriteLine("Converting {0}, Kind {1}, Ambiguous {2}", datAmbiguous, datAmbiguous.Kind, TimeZoneInfo.Local.IsAmbiguousTime(datAmbiguous))
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datAmbiguous), TimeZoneInfo.ConvertTimeToUtc(datAmbiguous).Kind)
Console.WriteLine()

Dim datInvalid As Date = #03/11/2007 2:30:00AM#    
Console.WriteLine("Converting {0}, Kind {1}, Invalid {2}", datInvalid, datInvalid.Kind, TimeZoneInfo.Local.IsInvalidTime(datInvalid))
Try
   Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datInvalid), TimeZoneInfo.ConvertTimeToUtc(datInvalid).Kind)
Catch e As ArgumentException
   Console.WriteLine("   {0}: Cannot convert {1} to UTC.", e.GetType().Name, datInvalid)
End Try
Console.WriteLine()

Dim datNearMax As Date = #12/31/9999 10:00:00PM#
Console.WriteLine("Converting {0}, Kind {1}", datNearMax, datNearMax.Kind)
Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNearMax), TimeZoneInfo.ConvertTimeToUtc(datNearMax).Kind)
Console.WriteLine()
'
' This example produces the following output if the local time zone 
' is Pacific Standard Time:
'
'    Converting 8/31/2007 2:26:28 PM, Kind Local:
'       ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
'    
'    Converting 8/31/2007 9:26:28 PM, Kind Utc
'       ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
'    
'    Converting 10/26/2007 1:32:00 PM, Kind Unspecified
'       ConvertTimeToUtc: 10/26/2007 8:32:00 PM, Kind Utc
'    
'    Converting 11/4/2007 1:30:00 AM, Kind Unspecified, Ambiguous True
'       ConvertTimeToUtc: 11/4/2007 9:30:00 AM, Kind Utc
'    
'    Converting 3/11/2007 2:30:00 AM, Kind Unspecified, Invalid True
'       ArgumentException: Cannot convert 3/11/2007 2:30:00 AM to UTC.
'    
'    Converting 12/31/9999 10:00:00 PM, Kind Unspecified
'       ConvertTimeToUtc: 12/31/9999 11:59:59 PM, Kind Utc

설명

수행 되는 정확한 변환은 값에 따라 달라 집니다 합니다 Kind 의 속성을 dateTime 매개 변수를 다음 표와 같이 합니다.The exact conversion performed depends on the value of the Kind property of the dateTime parameter, as the following table shows.

DateTime.Kind 속성DateTime.Kind property 변환Conversion
DateTimeKind.Local 현지 시간에서 utc (협정 세계시)로 변환합니다.Converts from local time to Coordinated Universal Time (UTC).
DateTimeKind.Unspecified 가정 dateTime 은 현지 시간 및 현지 시간에서 UTC로 변환 합니다.Assumes dateTime is local time and converts from local time to UTC.
DateTimeKind.Utc 반환 dateTime 변경 되지 않습니다.Returns dateTime unchanged.

경우 dateTime 해당이 메서드는 모호한 현지 시간으로 표준 로컬 시간을 가정 합니다.If dateTime corresponds to an ambiguous local time, this method assumes that it is standard local time. 하는 경우 dateTime 잘못 된 현지 시간, 메서드가 throw에 해당 하는 ArgumentException합니다.If dateTime corresponds to an invalid local time, the method throws an ArgumentException.

참고

현재 컴퓨터의 로컬 표준 시간대의이 오버 로드 여러 조정 규칙을 포함 합니다 ConvertTimeToUtc 메서드는 다른 결과를 반환할 수 있습니다 합니다 TimeZone.ToUniversalTimeDateTime.ToUniversalTime 메서드.If the current computer's local time zone includes multiple adjustment rules, this overload of the ConvertTimeToUtc method can return results that differ from the TimeZone.ToUniversalTime and DateTime.ToUniversalTime methods. TimeZone.ToUniversalTime 항상 현재 조정 규칙에서 표준 시간대 변환 여부 적용 dateTime 해당 날짜 범위 내에 있다고 합니다.TimeZone.ToUniversalTime always applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range. 실행 하는 경우 .NET Framework 3.5.NET Framework 3.5, DateTime.ToUniversalTime 도 현재 조정 규칙에서 표준 시간대 변환 여부에 적용 됩니다 dateTime 해당 날짜 범위 내에 있다고 합니다.And when executing on .NET Framework 3.5.NET Framework 3.5, DateTime.ToUniversalTime also applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range.

경우에 해당 UTC dateTime 이전의 DateTime.MinValue 이상 하는 DateTime.MaxValue,이 메서드가 반환 MinValue 또는 MaxValue각각.If the UTC equivalent of dateTime is earlier than DateTime.MinValue or later that DateTime.MaxValue, this method returns MinValue or MaxValue, respectively.

추가 정보

적용 대상