DateTimeOffset.UtcDateTime 属性

定义

获取一个 DateTime 值,该值表示当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间。

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

属性值

DateTime

当前 DateTimeOffset 对象的协调世界时 (UTC) 日期和时间。

示例

下面的示例演示如何使用该 UtcDateTime 属性显示 DateTimeOffset 值及其相应的 UTC 时间。

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
let offsetTime = DateTimeOffset(2007, 11, 25, 11, 14, 00, TimeSpan(3, 0, 0))
printfn $"{offsetTime} is equivalent to {offsetTime.UtcDateTime} {offsetTime.UtcDateTime.Kind}"
// 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 属性执行双重转换:

Kind返回DateTime的值的属性设置为 DateTimeKind.Utc

检索属性的值 UtcDateTime 等效于调用当前 DateTimeOffset 对象的 ToUniversalTime.DateTime 属性,但 Kind 后一 DateTime 个值的属性除外 DateTimeKind.Unspecified

适用于