rtimeformatdecimal

Convert decimal hours to HH:MM:SS


I'm looking for a way to convert decimal hours to HH:MM:SS

For instance, as input:

4.927778 hours

Desired output:

04:55:40

Solution

  • You can try something like below

    dh <- 4.927778
    strftime(as.POSIXct(dh * 60 * 60, origin = Sys.Date(), tz = "GMT"), format = "%H:%M:%S")
    ## [1] "04:55:40"