Reputation: 52228
How can we convert the output of Sys.time()
to character class without losing the timezone information (in this case the AEDT
) ?
Sys.time()
# [1] "2019-10-17 21:54:07 AEDT"
Sys.time() %>% as.character()
# [1] "2019-10-17 21:54:07"
# Desired output
"2019-10-17 21:54:07 AEDT"
Please note that I wish to avoid using any external libraries (just base R)
Upvotes: 3
Views: 122
Reputation: 3791
This gives you a character
x <- format(Sys.time(), usetz = TRUE)
str(x)
# chr "2019-10-17 22:13:45 AEDT"
usetz
is FALSE
by default, set that to TRUE
so it persists during the conversion.
Upvotes: 4