DateTimeOffset.DateTime Property

Definition

Gets a DateTime value that represents the date and time of the current DateTimeOffset object.

C#
public DateTime DateTime { get; }

Property Value

The date and time of the current DateTimeOffset object.

Examples

The following example illustrates the use of the DateTime property to convert the time returned by the Now and UtcNow properties to DateTime values.

C#
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.

Remarks

The DateTime property is not affected by the value of the Offset property.

This property returns both the date and the time component of a DateTimeOffset object, which makes it useful for performing DateTimeOffset to DateTime conversion. For example, if the DateTimeOffset object has a date and time value of "1/12/07 4:01pm + 7:30", the property returns a date of "1/12/07 4:01pm".

The value of the DateTime.Kind property of the returned DateTime object is DateTimeKind.Unspecified.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

See also