I'm using Ruby 2.4. I want to convert milliseconds to a readable hours, minutes, and seconds format. SO I have this method
def time_as_str(time_in_ms)
regex = /^(0*:?)*0*/
Time.at(time_in_ms.to_f/1000).utc.strftime("%H:%M:%S.%1N").sub!(regex, '')
end
The problem is, if my value in milliseconds is a day or greater, this function doesn't display the correct values. FOr instance, if I pass
2.4.0 :009 > TimeFormattingHelper.time_as_str(86400000)
=> ".0"
86400000 is a day in milliseconds (unless I've miscalculated). So I would expect the value to be "24:00:00". How do I correct the above to display the time formatted properly?