DateTimeOffset.UtcNow Properti

Definisi

DateTimeOffset Mendapatkan objek yang tanggal dan waktunya diatur ke tanggal dan waktu Waktu Universal Terkoordinasi (UTC) saat ini dan yang offset-nya adalah Zero.

public:
 static property DateTimeOffset UtcNow { DateTimeOffset get(); };
public static DateTimeOffset UtcNow { get; }
static member UtcNow : DateTimeOffset
Public Shared ReadOnly Property UtcNow As DateTimeOffset

Nilai Properti

Objek yang tanggal dan waktunya adalah Waktu Universal Terkoordinasi (UTC) saat ini dan yang offset-nya adalah Zero.

Contoh

Contoh berikut mengilustrasikan hubungan antara Waktu Universal Terkoordinasi (UTC) dan waktu setempat.

DateTimeOffset localTime = DateTimeOffset.Now;
DateTimeOffset utcTime = DateTimeOffset.UtcNow;

Console.WriteLine("Local Time:          {0}", localTime.ToString("T"));
Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString());
Console.WriteLine("UTC:                 {0}", utcTime.ToString("T"));
// If run on a particular date at 1:19 PM, the example produces
// the following output:
//    Local Time:          1:19:43 PM
//    Difference from UTC: -07:00:00
//    UTC:                 8:19:43 PM
let localTime = DateTimeOffset.Now
let utcTime = DateTimeOffset.UtcNow

printfn $"Local Time:          {localTime:T}"
printfn $"Difference from UTC: {localTime.Offset}"
printfn $"UTC:                 {utcTime:T}"

// If run on a particular date at 1:19 PM, the example produces
// the following output:
//    Local Time:          1:19:43 PM
//    Difference from UTC: -07:00:00
//    UTC:                 8:19:43 PM
Dim localTime As DateTimeOffset = DateTimeOffset.Now
Dim utcTime As DateTimeOffset = DateTimeOffset.UtcNow

Console.WriteLine("Local Time:          {0}", localTime.ToString("T"))
Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString())
Console.WriteLine("UTC:                 {0}", utcTime.ToString("T"))
' If run on a particular date at 1:19 PM, the example produces
' the following output:
'    Local Time:          1:19:43 PM
'    Difference from UTC: -07:00:00
'    UTC:                 8:19:43 PM

Keterangan

Properti UtcNow menghitung Universal Coordinated Time (UTC) saat ini berdasarkan waktu jam sistem lokal dan offset yang ditentukan oleh zona waktu sistem lokal.

Presisi komponen milidetik waktu UTC saat ini tergantung pada resolusi jam sistem. Pada Windows NT 3.5 dan yang lebih baru, dan sistem operasi Windows Vista, resolusi jam sekitar 10-15 milidetik.

Berlaku untuk

Lihat juga