DateTime 結構

定義

表示時間的瞬間,通常以一天的日期和時間表示。

JAVAscript 此類型會顯示為 Date 物件。

。網 使用 .NET 進行程式設計時,會隱藏此類型,而開發人員應該使用 System.DateTimeOffset 結構。

C++/CX 類似于 FILETIME ,但有重要的差異。 請參閱<備註>。

C++/WinRT 此類型是 std::chrono::time_point的特製化。 請參閱<備註>。

public value class DateTime
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.FoundationContract, 65536)]
struct time_point
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.FoundationContract), 65536)]
public struct DateTimeOffset
var dateTime = {
universalTime : /* Your value */
}
Public Structure DateTimeOffset
繼承
DateTime
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.FoundationContract (已於 v1.0 引進)

備註

JavaScript 和 Microsoft .NET 語言不會直接使用此類型。 在 JavaScript 中,DateTime 會投影為 Date 物件,並在 Microsoft .NET 中投影為 System.DateTimeOffset。 每個語言都會以透明方式處理個別語言的資料細微性和日期範圍轉換。

在 Visual C++ 元件延伸模組 (C++/CX) 中, DateTime.UniversalTime 值的資料細微性與 FILETIME (100 奈秒間隔) 相同。 如果是正值, DateTime.UniversalTime 值與 FILETIME 值相同,但只能表示最多 29000 C.E 的日期。負值代表 1601 年 1 月 1 日之前的間隔數目,而且可以表示回到大約 27,400 B.C.E 的日期。對於西曆,您可以使用 DateTimeFormatter 來建立 DateTime 的字串標記法,以在 Year 1 C.E 午夜之後的日期。

若要將 UniversalTime 轉換為 SYSTEMTIME,請使用 ULARGE_INTEGERint64 值轉換成 FILETIME,然後使用 FileTimeToSystemTime 取得 SYSTEMTIME

在 C++/WinRT 中, DateTime 類似于 C++/CX,因為它的資料細微性與 FILETIME相同。 不同于 C++/CX,它是 std::chrono::time_point 特製化,而不是不同的結構。 C++/WinRT 提供協助程式函式,可將 DateTimeFILETIME從 time_t轉換。 如需這些函式的詳細資訊,請參閱 winrt::clock 結構

欄位

UniversalTime

64 位帶正負號的整數,表示根據西曆) 在 160 (1 年 1 月 1 日午夜之前或之後 100 奈秒間隔的 100 奈秒間隔數。

注意

在 C++/WinRT 中,此欄位不存在,因為在該語言投影 DateTime 中是 std::chrono::time_point的特製化。 如果您需要原始整數值,請使用 time_point::time_since_epoch 來取得 std::chrono::d uration,並使用其 count 方法來取得原始計數。

適用於

另請參閱