Data
I have a vector of times, each in different timezones e.g
x = c("2024-01-05 11:12:13 UTC", "2024-01-10 12:13:14 CET", "2024-01-15 07:08:09 EST")
Question
How can I get info about the timezone for each element and use it to convert these data into one "universal" timezone, e.g. "UTC"?
Solutions using {base} or {lubridate} are preferred.
Attempt
dtf <-
tibble(
x <- c("2024-01-05 11:12:13 UTC", "2024-01-10 12:13:14 CET", "2024-01-15 07:08:09 EST")
y <- str_extract(x, "[^ ]+$")
)
dtf %>%
map(
y, ~ as_datetime(x, tz = y)
)
which gives NULL values.
Interesting. I don't know a lot about
lubridate::as_date(), I preferelubridate::ymd_hms(). Inlubridate::ymd_hms()(orparse_date_time()) , thetzargument as to be of length one. You were in the right path with withmap.I did my example with
with_tz(tzone="EST")to demonstrate an alternative to UTC representation.