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
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"
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) %% 1)*60,0)
paste(h,m,s,sep = ":")
#[1] "4:55:40"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With