Time zone disappears in output in R system time

date, r, time

Solution

Try this instead:

cat(format(Sys.time(),usetz = TRUE))

The print method for POSIXct objects calls `format` with `usetz = TRUE` which is why you see the time zone in the console (the print method is called behind the scenes).

Problem

I am trying to output the system date and time to a text file. When I do so, the time zone disappears. An example follows: ``` > Sys.time() [1] "2012-05-24 09:58:38 CDT" > currentTime <- Sys.time() > currentTime [1] "2012-05-24 09:58:49 CDT" > cat(as.character(currentTime), sep = "\n") 2012-05-24 09:58:49 ``` What happened to the time zone and how to I get it back?

Original source