共用方式為


DateTimeOffset.UtcDateTime 屬性

定義

取得 DateTime 值,這個值表示目前 DateTimeOffset 物件的 Coordinated Universal Time (UTC) 日期和時間。

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

屬性值

目前 DateTimeOffset 物件的 Coordinated Universal Time (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 會執行雙重轉換:

KindDateTime 回值的 屬性會設定為 DateTimeKind.Utc

擷取屬性的值 UtcDateTime 相當於呼叫目前 DateTimeOffset 物件的 ToUniversalTime.DateTime 屬性,但後者 DateTime 值的 屬性為 DateTimeKind.UnspecifiedKind

適用於