你好我已经定义了这个方法
def change_date
date = Date.today
start_date = date.change(year: 2015, month: (2 * 3)).at_beginning_of_quarter
p 'aaaaaa'
p start_date
end
给我 invalid date
error .change is not working or am I doing it in a wrong way 请指导我如何解决这个问题。提前致谢。
最佳答案
这是因为您指定的月份没有当天。
我的意思是当前月份(7 月)有 31 天,但您设置的月份(6 月)只有 30 天。您可以像这样更改代码:
# in Rails:
date = Date.today.beginning_of_month # or Date.today.change(day: 1)
然后将您的“更改”链接到 date
变量前面。
关于ruby-on-rails - .change 函数不适用于 ruby 中偶数月的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31739793/