Get last day of the month in Ruby

后端 未结 6 1576
-上瘾入骨i
-上瘾入骨i 2020-12-12 20:32

I made new object Date.new with args (year, month). After create ruby added 01 number of day to this object by default. Is there any way to add not first day, but last day o

6条回答
  •  旧时难觅i
    2020-12-12 21:20

    You can do something like that:

    def last_day_of_month?
       (Time.zone.now.month + 1.day) > Time.zone.now.month
    end
    
    Time.zone.now.day if last_day-of_month?
    

提交回复
热议问题