Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert time in hours from numeric to HMS format

How to convert numbers that represent time in hours from numeric to HMS format.

for example:

8.0 -> 08:00:00
0.5 -> 00:30:00
0.25 -> 00:15:00
like image 474
ronencozen Avatar asked Dec 05 '22 08:12

ronencozen


1 Answers

Convert to seconds, make use of seconds_to_periods from lubridate and change it to hms

hms::hms(lubridate::seconds_to_period(floor(v1 * 60 *60)))
#08:00:00
#00:30:00
#00:15:00

data

v1 <- c(8, 0.5, 0.25)
like image 154
akrun Avatar answered Dec 21 '22 23:12

akrun