See https://en.wikipedia.org/wiki/ISO_8601 and links therein for the complete standard.

parse_iso_8601(dates, default_tz = "UTC")

Arguments

dates

A character vector. An error is reported if the function cannot coerce this parameter to a character vector.

default_tz

Time zone to assume for dates that don't specify a time zone explicitly. Defaults to UTC, and an empty string means the local time zone.

Value

A POSIXct vector. NA is returned for the dates that parse_date could not parse.

Examples

# Missing fields
parse_iso_8601("2013-02-08 09")
#> [1] "2013-02-08 09:00:00 UTC"
parse_iso_8601("2013-02-08 09:30")
#> [1] "2013-02-08 09:30:00 UTC"

# Separator between date and time can be a 'T'
parse_iso_8601("2013-02-08T09")
#> [1] "2013-02-08 09:00:00 UTC"
parse_iso_8601("2013-02-08T09:30")
#> [1] "2013-02-08 09:30:00 UTC"
parse_iso_8601("2013-02-08T09:30:26")
#> [1] "2013-02-08 09:30:26 UTC"

# Fractional seconds, minutes, hours
parse_iso_8601("2013-02-08T09:30:26.123")
#> [1] "2013-02-08 09:30:26 UTC"
parse_iso_8601("2013-02-08T09:30.5")
#> [1] "2013-02-08 09:30:30 UTC"
parse_iso_8601("2013-02-08T09,25")
#> [1] "2013-02-08 09:15:00 UTC"

# Zulu time zone is UTC
parse_iso_8601("2013-02-08T09:30:26Z")
#> [1] "2013-02-08 09:30:26 UTC"

# ISO weeks, not very intuitive
parse_iso_8601("2013-W06-5")
#> [1] "2013-02-08 UTC"
parse_iso_8601("2013-W01-1")
#> [1] "2012-12-31 UTC"
parse_iso_8601("2009-W01-1")
#> [1] "2008-12-29 UTC"
parse_iso_8601("2009-W53-7")
#> [1] "2010-01-03 UTC"

# Day of the year
parse_iso_8601("2013-039")
#> [1] "2013-02-08 UTC"
parse_iso_8601("2013-039 09:30:26Z")
#> [1] "2013-02-08 09:30:26 UTC"