Class DateTimeExtensions
Static class containing extension methods for DateTime objects.
Inheritance
Namespace: Tableau.Migration
Assembly: Tableau.Migration.dll
Syntax
public static class DateTimeExtensions
Methods
CeilingDateTime(DateTime, TimeSpan)
Raises the date time to the nearest interval
Declaration
public static DateTime CeilingDateTime(this DateTime dt, TimeSpan interval)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dt | DateTime to raise |
| TimeSpan | interval | Interval to which to lower |
Returns
| Type | Description |
|---|---|
| DateTime | Raised date time |
EnsureUtcKind(DateTime)
Declaration
public static DateTime EnsureUtcKind(this DateTime value)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value |
Returns
| Type | Description |
|---|---|
| DateTime |
EnsureUtcKind(DateTime?)
Declaration
public static DateTime? EnsureUtcKind(this DateTime? value)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime? | value |
Returns
| Type | Description |
|---|---|
| DateTime? |
FloorDateTime(DateTime, TimeSpan)
Lowers the date time to the nearest interval
Declaration
public static DateTime FloorDateTime(this DateTime dt, TimeSpan interval)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dt | DateTime to lower |
| TimeSpan | interval | Interval to which to lower |
Returns
| Type | Description |
|---|---|
| DateTime | Lowered date time |
ParseFromIso8601(string, bool)
Parses a DateTime from a string that is in ISO-8601 format.
Declaration
public static DateTime ParseFromIso8601(this string value, bool ensureUtc = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| bool | ensureUtc |
Returns
| Type | Description |
|---|---|
| DateTime | The parsed DateTime value. |
ToIso8601(DateTime)
Gets the ISO-8601 DateTime string, preserves current DateTimeKind setting but truncates fractional seconds.
Declaration
public static string ToIso8601(this DateTime dateTime)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | dateTime |
Returns
| Type | Description |
|---|---|
| string |
TryParseFromIso8601(string?, bool)
Parses a Nullable<T> from a string that is in ISO-8601 format.
Declaration
public static DateTime? TryParseFromIso8601(this string? value, bool ensureUtc = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| bool | ensureUtc |
Returns
| Type | Description |
|---|---|
| DateTime? | The parsed DateTime value, or null if parsing failed. |
TryParseFromIso8601(string?, out DateTime, bool)
Attempts to parse a DateTime from a string that is in ISO-8601 format.
Declaration
public static bool TryParseFromIso8601(this string? value, out DateTime d, bool ensureUtc = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| DateTime | d | The DateTime to assign with the parsed value. |
| bool | ensureUtc |
Returns
| Type | Description |
|---|---|
| bool | True if the value was successfully parsed, otherwise false. |