How can I convert unix timestamp (milliseconds) and timezone in R?
I have data that has two columns time
and timezone
that has an event timestamp. Examples are:
time timezone
1433848856453 10800000
The timestamp seems to have fractional seconds in the information as well. I don't understand the timezone format, but it should be the equivalent unix format. I also need to store fractional seconds. How do I go from this to something like R?
2015-01-01 13:34:56.45 UTC
Note. This human readable date is not the actual converted unix timestamp value.
source to share
It looks like the column timezone
is the timezone offset in milliseconds. I'm guessing this means the timezone column will adjust for daylight saving time manually
Therefore, before converting to POSIXct
, add the time
and columns timezone
. You must also set tz
to "UTC"
so that no DST adjustments are made to your object POSIXct
.
R> time <- 1433848856453
R> timezone <- 10800000
R> options(digits.secs=3)
R> .POSIXct((time+timezone)/1000, tz="UTC")
[1] "2015-06-09 14:20:56.453 UTC"
source to share
I think this might be right for you.
aa <- 1433848856453
as.POSIXct(aa/1000, origin="1970-01-01")
[1] "2015-06-09 13:20:56.453 CEST"
Edit
Now I realized that my code is not reproducible due to my personal settings, but that might fix it and allow you to achieve your goal.
options(digits.secs=6)
source to share