Why do I see a difference when I convert a unix timestamp to datetime object in R?
> as.POSIXlt(1268736919, origin="1970-01-01", tz="America/New_York")
[1] "2010-03-16 06:55:19 EDT"
> as.POSIXct(1268736919, origin="1970-01-01", tz="America/New_York")
[1] "2010-03-16 11:55:19 EDT"
The result from POSIXlt is actually correct.
Also, is there a way to do this conversion without specifying the origin?
Thanks
The help page actually hints at a difference:
This stuff is finicky — I think there is an implicit TZ conversion happening for
as.POSIXct. Consider thatthe second one (using
as.POSIXct) does not return the original input. Unfortunately, Brian D. Ripley seems to be the only human having all the details here.Lastly, you can’t do it without the origin. But you could define wrappers that use the epoch as origin (as here) or use 2000-01-01 or … Just keep it consistent.