How to get the number of days in a given month in Ruby, accounting for year?

前端 未结 13 1238
暖寄归人
暖寄归人 2020-12-23 09:22

I\'m sure there\'s a good simple elegant one-liner in Ruby to give you the number of days in a given month, accounting for year, such as \"February 1997\". What is it?

13条回答
  •  天涯浪人
    2020-12-23 10:10

    revise the input for other format

    def days_in_a_month(date = "2012-02-01")
      date.to_date.end_of_month.day
    end
    

提交回复
热议问题