I have a datetime called dispatched_time which I am subtracting from Time.now which results in a float number ie: 302.332 which is a method called elapsed_time. I need to figure out a way to take the value of that number and format it into a time in my view. ie: 13:20.
I've tried to use elapsed_time.strftime("%H%M") but strftime won't process a float.
Can someone help me out with converting the float in seconds into a HH:MM format?
You could try Time.at(elapsed_time).utc.strftime("%H:%M")
. This should give you the hours/minutes between the two times, created as if it were a time itself. Note that this may not work as well if there are more than 24 hours between the two times, in which case you would need to add a days parameter ("%d"
) to the string passed to strftime
.
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