How convert decimal to POSIX time

前端 未结 3 1481
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 11:10

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

         sunrise           sunset
6.49055593325792 18.2873900837081

3条回答
  •  一向
    一向 (楼主)
    2020-11-29 11:19

    First convert the decimal representation to hours and minutes (if I understand it right)

    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"
    

提交回复
热议问题