Skip to content

parse

Parses the specified string and returns a DateTimeOffset object.

1
DateTimeOffset.parse(val: string):DateTimeOffset

Parses the given string in the specified format and returns a DateTimeOffset object.

1
DateTimeOffset.parse(val: string, format: string):DateTimeOffset

Parameters

string val
    A string representing the date and time.

string format
    The exact format: o, d, g, G, or a custom format with the parts listed in DateTimeOffset.toString.

Returns

A DateTimeOffset object representing the parsed date and time.

Remarks

When the input has no offset, the local offset is used: the user's in browser form scripts and the server's in server workflow scripts. Prefer an explicit Z or +/-HH:mm offset for values that cross users, tenants, or systems. Text that is not ISO 8601 is read with the culture: the invariant culture in server workflow scripts, and the user's language in browser form scripts.

When the text is not a valid date, server workflow scripts throw an error, and browser form scripts return null for compatibility with existing forms. Use DateTimeOffset.tryParse when the same code runs on both sides.

Without zzz in the format, the local offset is used.

Examples

Parse a timestamp with an explicit offset

1
var dt1 = DateTimeOffset.parse("2012-01-01T00:00:00+03:00");

Parse a local timestamp without an offset

1
var dt2 = DateTimeOffset.parse("2012-01-01T00:00:00");

Parse a timestamp with a custom format string

1
var dt1 = DateTimeOffset.parse("01.02.2012 13:30 +03:00", "dd.MM.yyyy HH:mm zzz");

See Also