Subtract n hours from a DateTime in Ruby

后端 未结 11 1355
别那么骄傲
别那么骄傲 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:56

    You could do this.

    adjusted_datetime = (datetime_from_form.to_time - n.hours).to_datetime
    

提交回复
热议问题