Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time zone disappears in output in R system time

Tags:

date

time

r

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?

like image 677
Jdub Avatar asked May 24 '12 15:05

Jdub


1 Answers

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).

like image 68
joran Avatar answered Sep 21 '22 03:09

joran