Calendar.NaiveDateTime.Parse
Summary↑
| iso8601(string) | Parses an ISO8601 datetime. Returns {:ok, NaiveDateTime struct, UTC offset in secods} In case there is no UTC offset, the third element of the tuple will be nil |
Functions
Parses an ISO8601 datetime. Returns {:ok, NaiveDateTime struct, UTC offset in secods} In case there is no UTC offset, the third element of the tuple will be nil.
Examples
# With offset
iex> iso8601("1996-12-19T16:39:57-0200")
{:ok, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, -7200}
# Without offset
iex> iso8601("1996-12-19T16:39:57")
{:ok, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, nil}
# With Z denoting 0 offset
iex> iso8601("1996-12-19T16:39:57Z")
{:ok, %Calendar.NaiveDateTime{year: 1996, month: 12, day: 19, hour: 16, min: 39, sec: 57, usec: nil}, 0}
# Invalid date
iex> iso8601("1996-13-19T16:39:57Z")
{:error, :invalid_datetime, nil}