parse_iso_8601: Parse date from an ISO 8601 format

View source: R/parsedate-package.r

parse_iso_8601R Documentation

Parse date from an ISO 8601 format

Description

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

Usage

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")
parse_iso_8601("2013-02-08 09:30")

# Separator between date and time can be a 'T'
parse_iso_8601("2013-02-08T09")
parse_iso_8601("2013-02-08T09:30")
parse_iso_8601("2013-02-08T09:30:26")

# Fractional seconds, minutes, hours
parse_iso_8601("2013-02-08T09:30:26.123")
parse_iso_8601("2013-02-08T09:30.5")
parse_iso_8601("2013-02-08T09,25")

# Zulu time zone is UTC
parse_iso_8601("2013-02-08T09:30:26Z")

# ISO weeks, not very intuitive
parse_iso_8601("2013-W06-5")
parse_iso_8601("2013-W01-1")
parse_iso_8601("2009-W01-1")
parse_iso_8601("2009-W53-7")

# Day of the year
parse_iso_8601("2013-039")
parse_iso_8601("2013-039 09:30:26Z")

parsedate documentation built on Oct. 29, 2022, 1:16 a.m.