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 回答1: 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" 回答2: You should be able to get an idea of what you need to do - a <- "4.927778 hours" a <- as.numeric(gsub(x = a,pattern = " hours", replacement = "")) h <- a%/% 1 m <- ((a%% 1)*60) %/% 1 s <- round((((a%% 1)*60) %