Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

datetime - How to convert unix timestamp (milliseconds) and timezone in R?

I have data which has two columns time and timezone that have the timestamp of events. Examples are:

time               timezone
1433848856453      10800000

It seems like the timestamp has fractional seconds in the information as well. I don't understand the timezone format but it must be an equivalent unix format. I need to preserve the fractional seconds as well. How do I go from that to something like in R?

2015-01-01 13:34:56.45 UTC

Note: This human readable date is not the actual converted values of the unix timestamp shown.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like the timezone column is the timezone offset, in milliseconds. I assume that means the timezone column will adjust for daylight saving time manually

So you should add the time and timezone columns before converting to POSIXct. You should also set the tz to "UTC" so no DST adjustments will be made to your POSIXct object.

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...