我有手术日期。我想创建有以下内容的本票:
day=1
month= the next month of operation_date
year= automatic
示例:
operation_date = 15/11/2010
promissory_note1_date = 1/12/2010
promissory_note2_date = 1/01/2011
promissory_note3_date = 1/02/2011
promissory_note4_date = 1/02/2011
如果存在四张期票
我怎样才能做到呢?
PD:请原谅我的语法
最佳答案
你可以做到
require "active_support"
require "active_support/core_ext/date/calculations"
# || require "active_support/all"
Date.today.at_beginning_of_month
#=> Wed, 01 Dec 2010
Date.today.at_beginning_of_month.next_month
#=> Sat, 01 Jan 2011
Date.today.at_beginning_of_month.next_month.next_month
#=> Tue, 01 Feb 2011
等等...
引用文献
Rails guide 3.0 - 6.1.4 - ActiveSupport - How to Load Core Extensions
Rails guide 3.0 - 6.1.4 - ActiveSupport - Extensions to date
关于ruby-on-rails - 如何在ruby中获取下个月的第一天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4399857/