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
305 views
in Technique[技术] by (71.8m points)

r - How convert decimal to POSIX time

I use a function from here to calculate the sunrise and sunset and it returns:

         sunrise           sunset
6.49055593325792 18.2873900837081

I am struggling (trying with strftime, POSIXct or as.Date functions) to convert it to real time, but so far without success.

As always, any suggestion is greatly appreciated.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

@Arun's strategy works, but it might be easier to just do:

x <- c(6.49055593325792, 18.2873900837081)
today<-as.POSIXct('2012-01-23 00:00:00 EST')
today + (3600*x)

# "2012-01-23 06:29:26 EST" "2012-01-23 18:17:14 EST"

That will get you the seconds as well.


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

...