DateTimeOffset.DateTime Vlastnost

Definice

DateTime Získá hodnotu, která představuje datum a čas aktuálního DateTimeOffset objektu.

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

Hodnota vlastnosti

DateTime

Datum a čas aktuálního DateTimeOffset objektu.

Příklady

Následující příklad znázorňuje použití DateTime vlastnosti k převodu času vráceného vlastnostmi Now a UtcNow vlastnostmi na DateTime hodnoty.

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.

Poznámky

Vlastnost DateTime není ovlivněna hodnotou Offset vlastnosti.

Tato vlastnost vrátí datum i časovou komponentu DateTimeOffset objektu, což usnadňuje DateTimeOffset DateTime převod. Pokud DateTimeOffset má například objekt hodnotu data a času 12.12.07 12:01 + 7:30, vrátí vlastnost datum "12.12.07 12:01".

Hodnota DateTime.Kind vlastnosti vráceného DateTime objektu je DateTimeKind.Unspecified.

Platí pro

Viz také