I currently use the difftime()
function to get the elapsed time between two Sys.time()
objects.
ie :
t1 <- Sys.time()
t2 <- Sys.time()
elapsed_time <- difftime(t2, t1)
The current output is something like :
5.188578 days
I would like to get an output that show the elapsed time this way :
5 days : 4 hours : 30 mins : 15 secs
or something similar to this.
I already tried the strptime()
function, but it seems to work for dates so I'm not sure how I could use it.
I also looked at the lubridate periods()
functions that seems to give output like this : "3m 12d 0H 0M 0S" (which would be great) but it doesn't seems to work with my elapsed_time object.
I also looked on stackoverflow and google but didn't find the answer I wanted.
so I was wondering if anyone could give me some clues on how to proceed. Thank you.
Edit : I found a somewhat good answer With Dave's comment and How to get time differences with output having multiple units page.
library(lubridate)
t1 <- Sys.time()
t2 <- Sys.time()
elapsed_time <- difftime(t2, t1)
as.period(elapsed_time)
Output result format is :
"3H 37M 55S"