Convert 12 hr time to 24 hr format in Ruby

前端 未结 4 513
后悔当初
后悔当初 2021-02-05 21:58

How do I convert \"11am\" and \"10pm\" into \"11:00\" and \"22:00\"? Is there a simple way using the date and time classes?

4条回答
  •  星月不相逢
    2021-02-05 22:40

    The Time class has no parse method, but DateTime has.

    require 'date'
    DateTime.parse("11pm").strftime("%H:%M") #=> "23:00"
    

提交回复
热议问题