how to convert 270921sec into days + hours + minutes + sec ? (ruby)

前端 未结 9 625
不知归路
不知归路 2020-12-02 06:09

I have a number of seconds. Let\'s say 270921. How can I display that number saying it is xx days, yy hours, zz minutes, ww seconds?

9条回答
  •  误落风尘
    2020-12-02 06:24

    Number of days = 270921/86400 (Number of seconds in day) = 3 days this is the absolute number

    seconds remaining (t) = 270921 - 3*86400 = 11721

    3.to_s + Time.at(t).utc.strftime(":%H:%M:%S")
    

    Which will produce something like 3:03:15:21

提交回复
热议问题