DateTimeExtensionsToDateTimeOffset Method

Gets the DateTimeOffset equivalent of this DateTime object.

Definition

Namespace: InnerDrive.Core
Assembly: InnerDrive.Core (in InnerDrive.Core.dll) Version: 5.2.9017.0
C#
public static DateTimeOffset ToDateTimeOffset(
	this DateTime dateTime
)

Parameters

dateTime  DateTime
This DateTime.

Return Value

DateTimeOffset
A DateTimeOffset.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type DateTime. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method allows users to convert a DateTime to a DateTimeOffset without throwing an ArgumentException if dateTime's DateTimeKind is Local. The behavior is as follows:
DateTimeKindResult
LocalA DateTimeOffset whose Offset is equal to the Local's UTC offset as of dateTime.
UtcA DateTimeOffset whose Offset is equal to the Zero.
UnspecifiedA DateTimeOffset whose Offset is equal to the Zero, and whose value is equal to dateTime.ToUniversalTime following the Base Class Library's rules for determining the value's actual time zone.

Example

C#
var testDate = new DateTime(2022, 11, 18, 0, 0, 0, DateTimeKind.Utc);
? testDate.ToDateTimeOffset();

// Result: 2022-11-18T00:00:00

See Also