The time zone disappears at the exit to system time R

I am trying to output the system date and time to a text file. When I do this, the time zone will disappear. The following is an example:

> 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 get it back?

+5
source share
1 answer

Try this instead:

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

The print method for POSIXct objects calls formatwith usetz = TRUE, so you see the time zone in the console (the print method is called backstage).

+7
source

All Articles