Ruby/Rails - How to convert seconds to time?

后端 未结 4 1731
既然无缘
既然无缘 2021-02-19 16:52

I need to perform the following conversion:

0     -> 12.00AM
1800  -> 12.30AM
3600  -> 01.00AM
...
82800 -> 11.00PM
84600 -> 11.30PM
4条回答
  •  猫巷女王i
    2021-02-19 17:38

    The simplest one-liner simply ignores the date:

    Time.at(82800).utc.strftime("%I:%M%p")
    
    #-> "11:00PM"
    

提交回复
热议问题