Search code examples
rdatetimeposix

Keep time zone information when converting POSIX object to string


I'm trying to convert a POSIX object to a string in R by using

as.character(Sys.time()) which returns "2021-09-28 08:38:13"

However, if I just run Sys.time() I get "2021-09-28 08:38:13 CEST".

How do I get the time zone information to be converted to the string, too?


Solution

  • use option usetz = TRUE

    as.character(Sys.time(), usetz = TRUE)