DateTime.from_iso8601


Description:

[ Version ( since = "2.56" ) ]
public DateTime.from_iso8601 (string text, TimeZone default_tz)

Creates a DateTime corresponding to the given ISO 8601 formatted string text.

ISO 8601 strings of the form <date><sep><time><tz> are supported.

<sep> is the separator and can be either 'T', 't' or ' '.

<date> is in the form:

  • `YYYY-MM-DD` - Year/month/day, e.g. 2016-08-24.
  • `YYYYMMDD` - Same as above without dividers.
  • `YYYY-DDD` - Ordinal day where DDD is from 001 to 366, e.g. 2016-237.
  • `YYYYDDD` - Same as above without dividers.
  • `YYYY-Www-D` - Week day where ww is from 01 to 52 and D from 1-7, e.g. 2016-W34-3.
  • `YYYYWwwD` - Same as above without dividers.

<time> is in the form:

  • `hh:mm:ss(.sss)` - Hours, minutes, seconds (subseconds), e.g. 22:10:42.123.
  • `hhmmss(.sss)` - Same as above without dividers.

<tz> is an optional timezone suffix of the form:

  • `Z` - UTC.
  • `+hh:mm` or `-hh:mm` - Offset from UTC in hours and minutes, e.g. +12:00.
  • `+hh` or `-hh` - Offset from UTC in hours, e.g. +12.

If the timezone is not provided in text it must be provided in default_tz (this field is otherwise ignored).

This call can fail (returning null) if text is not a valid ISO 8601 formatted string.

You should release the return value by calling g_date_time_unref when you are done with it.

Parameters:

text

an ISO 8601 formatted time string.

default_tz

a TimeZone to use if the text doesn't contain a timezone, or null.

Returns:

a new DateTime, or null