Description Arguments Details Value Examples
Extract date/time components from strings following one of the six formats specified in the NOTE-datetime ISO 8601 profile (https://www.w3.org/TR/NOTE-datetime).
x |
a character vector. |
For character strings in one of the formats in the profile, the corresponding date/time components are extracted, with seconds and decimal fractions of seconds combined. Other (malformed) strings are warned about.
The extracted components for each string are gathered into a named list with elements of the appropriate type (integer for year to min; double for sec; character for the time zone designator). The object returned is a (suitably classed) list of such named lists. This internal representation may change in future versions.
One can subscript such ISO 8601 date/time objects using [
and
extract components using $
(where missing components will
result in NA
s), and convert them to the standard R date/time
classes using as.Date()
, as.POSIXct()
and
as.POSIXlt()
(incomplete elements will convert to
suitably missing elements). In addition, there are print()
and
as.data.frame()
methods for such objects.
An object inheriting from class "ISO_8601_datetime"
with the
extracted date/time components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Use the examples from <https://www.w3.org/TR/NOTE-datetime>, plus one
## in UTC.
x <- c("1997",
"1997-07",
"1997-07-16",
"1997-07-16T19:20+01:00",
"1997-07-16T19:20:30+01:00",
"1997-07-16T19:20:30.45+01:00",
"1997-07-16T19:20:30.45Z")
y <- parse_ISO_8601_datetime(x)
y
## Conversions: note that "incomplete" elements are converted to
## "missing".
as.Date(y)
as.POSIXlt(y)
## Subscripting and extracting components:
head(y, 3)
y$mon
|
year mon day hour min sec tzd
1997 1997
1997-07 1997 7
1997-07-16 1997 7 16
1997-07-16T19:20+01:00 1997 7 16 19 20 +01:00
1997-07-16T19:20:30+01:00 1997 7 16 19 20 30 +01:00
1997-07-16T19:20:30.45+01:00 1997 7 16 19 20 30.45 +01:00
1997-07-16T19:20:30.45Z 1997 7 16 19 20 30.45 Z
[1] NA NA "1997-07-16" "1997-07-16" "1997-07-16"
[6] "1997-07-16" "1997-07-16"
[1] NA NA
[3] NA NA
[5] "1997-07-16 18:20:30 UTC" "1997-07-16 18:20:30 UTC"
[7] "1997-07-16 19:20:30 UTC"
year mon day hour min sec tzd
1997 1997
1997-07 1997 7
1997-07-16 1997 7 16
[1] NA 7 7 7 7 7 7
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.