Поделиться через


DateTimeOffset.UtcDateTime Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property UtcDateTime As DateTime
public DateTime UtcDateTime { get; }

Property Value

Type: System.DateTime
An object whose value represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

Remarks

The UtcDateTime property performs a dual conversion:

  • It converts the date and time of the current DateTimeOffset object to Coordinated Universal Time (UTC). The conversion is performed by subtracting the value of the Offset property from the date and time of the current DateTimeOffset object.

  • It converts the DateTimeOffset value to a DateTime value.

The Kind property of the returned DateTime value is set to DateTimeKind.Utc.

Retrieving the value of the UtcDateTime property is equivalent to calling the current DateTimeOffset object's ToUniversalTime.DateTime property, except that the Kind property of the latter DateTime value is DateTimeKind.Unspecified.

Examples

The following example shows how to use of the UtcDateTime property to display a DateTimeOffset value and its corresponding UTC time.

Dim offsetTime As New DateTimeOffset(#11/25/2007 11:14:00 AM#, _
                  New TimeSpan(3, 0, 0))
outputBlock.Text &= String.Format("{0} is equivalent to {1} {2}", _
                  offsetTime.ToString(), _
                  offsetTime.UtcDateTime.ToString(), _
                  offsetTime.UtcDateTime.Kind.ToString()) & vbCrLf
DateTimeOffset offsetTime = new DateTimeOffset(2007, 11, 25, 11, 14, 00,
                            new TimeSpan(3, 0, 0));
outputBlock.Text += String.Format("{0} is equivalent to {1} {2}",
                  offsetTime.ToString(),
                  offsetTime.UtcDateTime.ToString(),
                  offsetTime.UtcDateTime.Kind.ToString()) + "\n";

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.