DateTimeOffset.DateTime Eigenschaft

Definition

Ruft einen DateTime-Wert ab, der die Datums- und Uhrzeitkomponente des aktuellen DateTimeOffset-Objekts darstellt.

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

Eigenschaftswert

DateTime

Das Datum und die Uhrzeit des aktuellen DateTimeOffset-Objekts.

Beispiele

Im folgenden Beispiel wird die Verwendung der DateTime Eigenschaft veranschaulicht, um die von den Now UtcNow Werten zurückgegebene Zeit in DateTime Werte zu konvertieren.

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.

Hinweise

Die DateTime Eigenschaft ist vom Wert der Offset Eigenschaft nicht betroffen.

Diese Eigenschaft gibt sowohl das Datum als auch die Uhrzeitkomponente eines DateTimeOffset Objekts zurück, was es für die DateTime Konvertierung DateTimeOffset nützlich macht. Wenn das DateTimeOffset Objekt beispielsweise einen Datums- und Uhrzeitwert von "1/12/07 4:01pm + 7:30" aufweist, gibt die Eigenschaft ein Datum von "1/12/07 4:01pm" zurück.

Der Wert der DateTime.Kind Eigenschaft des zurückgegebenen DateTime Objekts ist DateTimeKind.Unspecified.

Gilt für

Siehe auch