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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With