DateTimeOffset Implicit Conversion (DateTime to DateTimeOffset)

 
equivalentCodeEntityM:System.DateTimeOffset.#ctor(System.DateTime)

Defines an implicit conversion of a DateTime object to a DateTimeOffset object.

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

public:
static operator DateTimeOffset (
	DateTime dateTime
)

Parameters

dateTime
Type: System::DateTime

The object to convert.

Return Value

Type: System::DateTimeOffset

The converted object.

Exception Condition
ArgumentOutOfRangeException

The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than MinValue.

-or-

The UTC date and time that results from applying the offset is later than MaxValue.

The Implicit(DateTime to DateTimeOffset) method enables the compiler to automatically convert a DateTime object to a DateTimeOffset object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). It defines a widening conversion that does not involve data loss and does not throw an OverflowException. The Implicit(DateTime to DateTimeOffset) method makes code such as the following possible:

No code example is currently available or this language may not be supported.

This method is equivalent to the DateTimeOffset constructor. The offset of the resulting DateTimeOffset object depends on the value of the DateTime::Kind property of the dateTime parameter:

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: