DateTimeOffset.UtcDateTime 属性

定义

获取一个 DateTime 值,该值表示当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间。Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

public:
 property DateTime UtcDateTime { DateTime get(); };
public DateTime UtcDateTime { get; }
member this.UtcDateTime : DateTime
Public ReadOnly Property UtcDateTime As DateTime

属性值

DateTime

当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间。The Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object.

示例

下面的示例演示如何使用 UtcDateTime 属性来显示 DateTimeOffset 值及其相应的 UTC 时间。The following example shows how to use of the UtcDateTime property to display a DateTimeOffset value and its corresponding UTC time.

DateTimeOffset offsetTime = new DateTimeOffset(2007, 11, 25, 11, 14, 00,
                            new TimeSpan(3, 0, 0));
Console.WriteLine("{0} is equivalent to {1} {2}",
                  offsetTime.ToString(),
                  offsetTime.UtcDateTime.ToString(),
                  offsetTime.UtcDateTime.Kind.ToString());
// The example displays the following output:
//       11/25/2007 11:14:00 AM +03:00 is equivalent to 11/25/2007 8:14:00 AM Utc
Dim offsetTime As New DateTimeOffset(#11/25/2007 11:14AM#, _
                  New TimeSpan(3, 0, 0))
Console.WriteLine("{0} is equivalent to {1} {2}", _
                  offsetTime.ToString(), _
                  offsetTime.UtcDateTime.ToString(), _
                  offsetTime.UtcDateTime.Kind.ToString())      
' The example displays the following output:
'       11/25/2007 11:14:00 AM +03:00 is equivalent to 11/25/2007 8:14:00 AM Utc      

注解

UtcDateTime属性执行双重转换:The UtcDateTime property performs a dual conversion:

Kind返回的值的属性 DateTime 设置为 DateTimeKind.UtcThe Kind property of the returned DateTime value is set to DateTimeKind.Utc.

检索属性的值 UtcDateTime 等效于调用当前 DateTimeOffset 对象的 ToUniversalTime.DateTime 属性,只不过 Kind 后一个值的属性 DateTimeDateTimeKind.UnspecifiedRetrieving 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.

适用于