Partager via


DateTimeOffset.DateTime Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property DateTime As DateTime
public DateTime DateTime { get; }

Property Value

Type: System.DateTime
An object whose value represents the date and time of the current DateTimeOffset object.

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.

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.

Dim offsetDate As DateTimeOffset
Dim regularDate As Date

offsetDate = DateTimeOffset.Now
regularDate = offsetDate.DateTime
outputBlock.Text &= String.Format("{0} converts to {1}, Kind {2}.", _
                  offsetDate.ToString(), _
                  regularDate, _
                  regularDate.Kind) & vbCrLf

offsetDate = DateTimeOffset.UtcNow
regularDate = offsetDate.DateTime
outputBlock.Text &= String.Format("{0} converts to {1}, Kind {2}.", _
                  offsetDate.ToString(), _
                  regularDate, _
                  regularDate.Kind) & vbCrLf
' 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.                        
DateTimeOffset offsetDate;
DateTime regularDate;

offsetDate = DateTimeOffset.Now;
regularDate = offsetDate.DateTime;
outputBlock.Text += String.Format("{0} converts to {1}, Kind {2}.",
                  offsetDate.ToString(),
                  regularDate,
                  regularDate.Kind) + "\n";

offsetDate = DateTimeOffset.UtcNow;
regularDate = offsetDate.DateTime;
outputBlock.Text += String.Format("{0} converts to {1}, Kind {2}.",
                  offsetDate.ToString(),
                  regularDate,
                  regularDate.Kind) + "\n";
// 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.                        

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.