Is there any efficient way, how to convert from GMT to EST in R?
This is what I tried:
d1 <- as.POSIXlt(as.POSIXct("2001-05-15 12:30:00"), tz="GMT")
[1] "2001-05-15 10:30:00 GMT"
as.POSIXct(as.character(d1),tz="EST")
[1] "2001-05-15 10:30:00 EST"
Actually there's no "conversion" in a deep sense. POSIXct
objects are always stored as the number of seconds since epoch (midnight UTC on Jan 1 1970).
The conversion you're after is "superficial" in the sense that all you're changing is how your object is displayed.
This is controlled by the tzone
attribute of a POSIXct
object.
So, assuming attr(x, 'tzone')
is already GMT for your object x
, you can just write:
attr(x, 'tzone') = 'EST'
to change this superficial behavior in your desired way.