我使用这里的函数来计算日出和日落时间,它返回:
sunrise sunset
6.49055593325792 18.2873900837081
我正在努力(尝试使用strftime
、POSIXct
或as.Date
函数)将其转换为实际时间,但到目前为止没有成功。
如往常一样,非常感谢任何建议。
我使用这里的函数来计算日出和日落时间,它返回:
sunrise sunset
6.49055593325792 18.2873900837081
我正在努力(尝试使用strftime
、POSIXct
或as.Date
函数)将其转换为实际时间,但到目前为止没有成功。
如往常一样,非常感谢任何建议。
@Arun的策略可行,但只是做以下操作可能更容易:
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"
那将会给你秒数。
首先将十进制表示转换为小时和分钟(如果我理解正确的话)
x <- c(6.49055593325792, 18.2873900837081)
# if 6.49 equals 6.49 hours, then do this.
x.m <- paste(floor(x), round((x-floor(x))*60), sep=":")
> x.m
# [1] "6:29" "18:17"
> strptime(x.m, format="%H:%M")
# [1] "2013-01-23 06:29:00" "2013-01-23 18:17:00"
# Use these two lines for 24-hour format
sunrise <- format(as.POSIXct(sunrise*3600, origin="2001-01-01", "GMT"), "%H:%M")
sunset <- format(as.POSIXct(sunset*3600, origin="2001-01-01", "GMT"), "%H:%M")
# Use these two lines for 12-hour format (AM/PM)
sunrise <- format(as.POSIXct(sunrise*3600, origin="2001-01-01", "GMT"), "%I:%M %p")
sunset <- format(as.POSIXct(sunset*3600, origin="2001-01-01", "GMT"), "%I:%M %p")