Ruby: combine Date and Time objects into a DateTime

后端 未结 6 1651
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 13:18

Simple question, but I can\'t find a good or definitive answer. What is the best and most efficient way to combine Ruby Date and Time objects (objects, not

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 14:12

    Simple:

    Date.new(2015, 2, 10).to_datetime + Time.parse("16:30").seconds_since_midnight.seconds
    
    # => Object: Tue, 10 Feb 2015 16:30:00 +0000
    

    You gotta love Ruby!

提交回复
热议问题