DateUtilsFromISO8601String Method

This method is used to convert an ISO 8601 formatted date string to a DateTime value that it represents.

Definition

Namespace: EWSoftware.PDI
Assembly: EWSoftware.PDI (in EWSoftware.PDI.dll) Version: 2023.1.2.0
public static DateTime FromISO8601String(
	string dateTimeText,
	bool toLocalTime
)

Parameters

dateTimeText  String
The ISO 8601 formatted date to parse.
toLocalTime  Boolean
If true and the string is in a universal time format, the value is converted to local time before being returned. If false, it is returned as a universal time value.

Return Value

DateTime
The specified string converted to a local date/time

Remarks

The Parse(String) method is capable of parsing a string in a very specific layout of the ISO 8601 format (SortableDateTimePattern). However, if the string deviates even slightly from that pattern, it cannot be parsed. This method takes an ISO 8601 formatted date string in any of various formats and returns the DateTime value that it represents.

This method does not handle all possible forms of the ISO 8601 format, just those related to date and time values (YYYY-MM-DDTHH:MM:SS.MMMM+HH:MM). Date and time separators (except the 'T') are optional as is the time zone specifier. The time indicator ('T') and the time value can be omitted entirely if not needed. A 'Z' (Zulu) can appear in place of the time zone specifier to indicate universal time. Date/times in universal time format or with a time zone offset are converted to local time if the bToLocalTime parameter is set to true. All other values are assumed to be local time already and will be returned unmodified as are date-only values.

Exceptions

ArgumentExceptionThis is thrown if the specified date/time string is not valid

See Also