Is there an add_days in ruby datetime?

后端 未结 6 1296
生来不讨喜
生来不讨喜 2020-12-25 10:59

In C#, There is a method AddDays([number of days]) in DateTime class.

Is there any kind of method like this in ruby?

6条回答
  •  情话喂你
    2020-12-25 11:50

    I think next_day is more readable than + version.

    require 'date'
    
    DateTime.new(2016,5,17)
    # => #
    DateTime.new(2016,5,17).next_day(10)
    # => #
    Date.new(2016,5,17)
    # => #
    Date.new(2016,5,17).next_day(10)
    # => #
    

    http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html#method-i-next_day.

提交回复
热议问题