DateTimeOffset.DateTime Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
DateTime Mendapatkan nilai yang menunjukkan tanggal dan waktu objek saat iniDateTimeOffset.
public:
property DateTime DateTime { DateTime get(); };
public DateTime DateTime { get; }
member this.DateTime : DateTime
Public ReadOnly Property DateTime As DateTime
Nilai Properti
Tanggal dan waktu objek saat ini DateTimeOffset .
Contoh
Contoh berikut mengilustrasikan penggunaan DateTime properti untuk mengonversi waktu yang dikembalikan oleh Now properti dan UtcNow menjadi DateTime nilai.
DateTimeOffset offsetDate;
DateTime regularDate;
offsetDate = DateTimeOffset.Now;
regularDate = offsetDate.DateTime;
Console.WriteLine("{0} converts to {1}, Kind {2}.",
offsetDate.ToString(),
regularDate,
regularDate.Kind);
offsetDate = DateTimeOffset.UtcNow;
regularDate = offsetDate.DateTime;
Console.WriteLine("{0} converts to {1}, Kind {2}.",
offsetDate.ToString(),
regularDate,
regularDate.Kind);
// If run on 3/6/2007 at 17:11, produces the following output:
//
// 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
// 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
let offsetDate = DateTimeOffset.Now
let regularDate = offsetDate.DateTime
printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}."
let offsetDate = DateTimeOffset.UtcNow
let regularDate = offsetDate.DateTime
printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}."
// If run on 3/6/2007 at 17:11, produces the following output:
//
// 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
// 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
Dim offsetDate As DateTimeOffset
Dim regularDate As Date
offsetDate = DateTimeOffset.Now
regularDate = offsetDate.DateTime
Console.WriteLine("{0} converts to {1}, Kind {2}.", _
offsetDate.ToString(), _
regularDate, _
regularDate.Kind)
offsetDate = DateTimeOffset.UtcNow
regularDate = offsetDate.DateTime
Console.WriteLine("{0} converts to {1}, Kind {2}.", _
offsetDate.ToString(), _
regularDate, _
regularDate.Kind)
' If run on 3/6/2007 at 17:11, produces the following output:
'
' 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
' 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
Keterangan
Properti DateTime tidak dipengaruhi oleh nilai Offset properti .
Properti ini mengembalikan komponen DateTimeOffset tanggal dan waktu objek, yang membuatnya berguna untuk melakukan DateTimeOffsetDateTime konversi. Misalnya, jika DateTimeOffset objek memiliki nilai tanggal dan waktu "1/12/07 16:01pm + 7:30", properti mengembalikan tanggal "1/12/07 16:01".
Nilai DateTime.Kind properti objek yang dikembalikan DateTime adalah DateTimeKind.Unspecified.