Subtract n hours from a DateTime in Ruby

后端 未结 11 1335
别那么骄傲
别那么骄傲 2020-12-14 06:02

I have a Ruby DateTime which gets filled from a form. Additionally I have n hours from the form as well. I\'d like to subtract those n hours from the previous DateTime. (To

11条回答
  •  天命终不由人
    2020-12-14 06:49

    The advance method is nice if you want to be more explicit about behavior like this.

    adjusted = time_from_form.advance(:hours => -n)
    

提交回复
热议问题