Class DateTimeExtensions
Extension methods for DateTime.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Extensions
Assembly: NodaTime.dll
Syntax
public static class DateTimeExtensions
Methods
ToInstant(DateTime)
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static Instant ToInstant(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The DateTime to convert. |
Returns
Type | Description |
---|---|
Instant | An Instant value representing the same instant in time as dateTime . |
Remarks
This is a convenience method which calls FromDateTimeUtc(DateTime).
Exceptions
Type | Condition |
---|---|
ArgumentException | dateTime does not have a kind of Utc . |
ToLocalDateTime(DateTime)
Converts a DateTime of any kind to LocalDateTime.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalDateTime ToLocalDateTime(this DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
DateTime | dateTime | The DateTime to convert. |
Returns
Type | Description |
---|---|
LocalDateTime | A new LocalDateTime with the same values as dateTime . |
Remarks
This is a convenience method which calls FromDateTime(DateTime).