Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Static class: RT.Util.ExtensionMethods.DateTimeExtensions

Summary

Provides extension methods on the DateTime type.

Static methods

int
Nanosecond(this DateTime datetime)
Inexplicably, the DateTime type does not offer any way of retrieving the full precision of the underlying data other than via Ticks or the ToString method. This extension method fills in the void.
DateTime
ParseIso(string str)
Parse the specified string as an ISO-formatted DateTime. See DateTimeExtensions.TryParseIso(string, out DateTime) for more info.
DateTime?
ParseIsoNullable(string str)
Parse the specified string as an ISO-formatted DateTime. Returns null if the string is null or cannot be parsed. See DateTimeExtensions.TryParseIso(string, out DateTime) for more info.
string
ToIsoString(this DateTime datetime, IsoDatePrecision precision = IsoDatePrecision.Seconds, IsoDateFormat format = IsoDateFormat.HumanReadable, bool includeTimezone = false)
Returns a string representation of the date/time in an ISO-8601 compatible (or very close) format.
string
ToIsoStringCustom(this DateTime datetime, IsoDatePrecision precision = IsoDatePrecision.Full, char? charInDate = -, char? charInTime = :, char? charBetween = , bool includeTimezone = false)
Returns a string representation of the date/time in an ISO-8601-like format. The date/time components are always ordered from largest (year) to smallest (nanoseconds), and they are always specified as a fixed-width numeric value. The separators between the parts can be customized.
string
ToIsoStringOptimal(this DateTime datetime, IsoDateFormat format = IsoDateFormat.HumanReadable, IsoDatePrecision minPrecision = IsoDatePrecision.Days, IsoDatePrecision maxPrecision = IsoDatePrecision.Full, bool includeTimezone = false)
Returns a string representation of the date/time in an ISO-8601-like format. The function will omit higher-precision parts whose values are zeroes, as permitted by the standard.
string Returns a string representation of the date/time in an ISO-8601-like format. Use this if the result must be round-trippable without losing any information. The function will omit higher-precision parts whose values are zeroes, as permitted by the standard.
DateTime
TruncatedToDays(this DateTime datetime)
Returns a copy of this DateTime, truncated to whole days.
DateTime
TruncatedToMilliseconds(this DateTime datetime)
Returns a copy of this DateTime, truncated to whole milliseconds.
DateTime
TruncatedToMinutes(this DateTime datetime)
Returns a copy of this DateTime, truncated to whole minutes.
DateTime
TruncatedToSeconds(this DateTime datetime)
Returns a copy of this DateTime, truncated to whole seconds.
bool
TryParseIso(string str, out DateTime result)

Attempts to parse the specified string as an ISO-formatted DateTime. The formats supported are guided by ISO-8601, but do not match it exactly. Strings with no timezone information are parsed into DateTimeKind.Unspecified.

ISO-8601 features not supported: day numbers; week numbers; time offsets; comma for decimal separation.

Features supported not in ISO-8601: '-' separator for the basic format; date shortening; timezone marker for date-only strings.