DateTimeOffset.ToUniversalTime 메서드

정의

현재 DateTimeOffset 개체를 UTC(협정 세계시)를 나타내는 DateTimeOffset 값으로 변환합니다.Converts the current DateTimeOffset object to a DateTimeOffset value that represents the Coordinated Universal Time (UTC).

``````public:
DateTimeOffset ToUniversalTime();``````
``public DateTimeOffset ToUniversalTime ();``
``member this.ToUniversalTime : unit -> DateTimeOffset``
``Public Function ToUniversalTime () As DateTimeOffset``

반환

UTC(협정 세계시)로 변환된 현재 DateTimeOffset 개체의 날짜와 시간을 나타내는 개체입니다.An object that represents the date and time of the current DateTimeOffset object converted to Coordinated Universal Time (UTC).

예제

다음 예제에서는 ToUniversalTime 메서드를 호출 하 여 현지 시간과 여러 다른 시간을 UTC (협정 세계시)로 변환 합니다.The following example calls the ToUniversalTime method to convert a local time and several other times to Coordinated Universal Time (UTC).

``````DateTimeOffset localTime, otherTime, universalTime;

// Define local time in local time zone
localTime = new DateTimeOffset(new DateTime(2007, 6, 15, 12, 0, 0));
Console.WriteLine("Local time: {0}", localTime);
Console.WriteLine();

// Convert local time to offset 0 and assign to otherTime
otherTime = localTime.ToOffset(TimeSpan.Zero);
Console.WriteLine("Other time: {0}", otherTime);
Console.WriteLine("{0} = {1}: {2}",
localTime, otherTime,
localTime.Equals(otherTime));
Console.WriteLine("{0} exactly equals {1}: {2}",
localTime, otherTime,
localTime.EqualsExact(otherTime));
Console.WriteLine();

// Convert other time to UTC
universalTime = localTime.ToUniversalTime();
Console.WriteLine("Universal time: {0}", universalTime);
Console.WriteLine("{0} = {1}: {2}",
otherTime, universalTime,
universalTime.Equals(otherTime));
Console.WriteLine("{0} exactly equals {1}: {2}",
otherTime, universalTime,
universalTime.EqualsExact(otherTime));
Console.WriteLine();
// The example produces the following output to the console:
//    Local time: 6/15/2007 12:00:00 PM -07:00
//
//    Other time: 6/15/2007 7:00:00 PM +00:00
//    6/15/2007 12:00:00 PM -07:00 = 6/15/2007 7:00:00 PM +00:00: True
//    6/15/2007 12:00:00 PM -07:00 exactly equals 6/15/2007 7:00:00 PM +00:00: False
//
//    Universal time: 6/15/2007 7:00:00 PM +00:00
//    6/15/2007 7:00:00 PM +00:00 = 6/15/2007 7:00:00 PM +00:00: True
//    6/15/2007 7:00:00 PM +00:00 exactly equals 6/15/2007 7:00:00 PM +00:00: True
``````
``````Dim localTime, otherTime, universalTime As DateTimeOffset

' Define local time in local time zone
localTime = New DateTimeOffset(#6/15/2007 12:00:00PM#)
Console.WriteLine("Local time: {0}", localTime)
Console.WriteLine()

' Convert local time to offset 0 and assign to otherTime
otherTime = localTime.ToOffset(TimeSpan.Zero)
Console.WriteLine("Other time: {0}", otherTime)
Console.WriteLine("{0} = {1}: {2}", _
localTime, otherTime, _
localTime.Equals(otherTime))
Console.WriteLine("{0} exactly equals {1}: {2}", _
localTime, otherTime, _
localTime.EqualsExact(otherTime))
Console.WriteLine()

' Convert other time to UTC
universalTime = localTime.ToUniversalTime()
Console.WriteLine("Universal time: {0}", universalTime)
Console.WriteLine("{0} = {1}: {2}", _
otherTime, universalTime, _
universalTime.Equals(otherTime))
Console.WriteLine("{0} exactly equals {1}: {2}", _
otherTime, universalTime, _
universalTime.EqualsExact(otherTime))
Console.WriteLine()
' The example produces the following output to the console:
'    Local time: 6/15/2007 12:00:00 PM -07:00
'
'    Other time: 6/15/2007 7:00:00 PM +00:00
'    6/15/2007 12:00:00 PM -07:00 = 6/15/2007 7:00:00 PM +00:00: True
'    6/15/2007 12:00:00 PM -07:00 exactly equals 6/15/2007 7:00:00 PM +00:00: False
'
'    Universal time: 6/15/2007 7:00:00 PM +00:00
'    6/15/2007 7:00:00 PM +00:00 = 6/15/2007 7:00:00 PM +00:00: True
'    6/15/2007 7:00:00 PM +00:00 exactly equals 6/15/2007 7:00:00 PM +00:00: True
``````

설명

이 메서드는 Offset 속성이 0으로 설정 된 DateTimeOffset 개체를 반환 합니다.This method returns a DateTimeOffset object whose Offset property is set to zero.

현재 DateTimeOffset 개체의 값과 메서드 호출에서 반환 되는 DateTimeOffset 개체의 값이 모두 동일한 시점을 나타냅니다.Both the value of the current DateTimeOffset object and the value of the DateTimeOffset object returned by the method call represent the same point in time. 즉, 둘 다 DateTimeOffset.Equals(DateTimeOffset, DateTimeOffset) 메서드에 전달 되는 경우 메서드는 `true`를 반환 합니다.That is, if both are passed to the DateTimeOffset.Equals(DateTimeOffset, DateTimeOffset) method, the method will return `true`.