I want to get start and end date of month in ruby on rails
. User enter integer value from 1..12. If user enter 1 then JAN
start_date,end_date If user enter 2 then FEB
start_date,end_date If user enter 3 then MARCH
start_date,end_date and so on
我希望在ruby上获得月份的开始和结束日期。用户输入1..12的整数值。如果用户输入1然后是JAN start_date,则end_date如果用户输入2则为FEB start_date,end_date如果用户输入3则为MARCH start_date,end_date等等
1 个解决方案
#1
13
There are built-in methods in active_support (part of Rails):
active_support中有内置方法(Rails的一部分):
month_number = 5 # user-provided month number
month_beginning = Date.new(Date.today.year, month_number)
# => Sun, 01 May 2016
month_ending = month_beginning.end_of_month
# => Tue, 31 May 2016
#1
13
There are built-in methods in active_support (part of Rails):
active_support中有内置方法(Rails的一部分):
month_number = 5 # user-provided month number
month_beginning = Date.new(Date.today.year, month_number)
# => Sun, 01 May 2016
month_ending = month_beginning.end_of_month
# => Tue, 31 May 2016