Convert duration to hours:minutes:seconds (or similar) in Rails 3 or Ruby

后端 未结 13 761
一整个雨季
一整个雨季 2021-01-29 23:52

I have a feeling there is a simple/built-in way to do this but I can\'t find it.

I have a duration (in seconds) in an integer and I want to display it in a friendly form

13条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 00:30

    Be careful with the duration longer than one day.

    (timing/3600).to_i.to_s.rjust(2,'0') + ":"+Time.at(timing).utc.strftime("%M:%S")
    

提交回复
热议问题