我有一个要求,我必须填写下拉列表,其中包含特定年份中所有周的列表,如图所示
如何根据使用jquery或Rails的年份动态实现列表?
答案 0 :(得分:0)
这可能会对您有所帮助:
date1 = Date.today.beginning_of_year
date2 = Date.today.end_of_year
weeks = []
while date2>date1 do
weeks << [date1.beginning_of_week, date1.end_of_week]
date1=date1+7.days
end
您还可以根据需要格式化日期,然后再将其推送到数组。
答案 1 :(得分:0)
start_date = Date.current.beginning_of_year
end_date = Date.current.end_of_year
weeks = []
(start_date..end_date).to_a.in_groups_of(7).each do |range|
weeks << "#{range.first} to #{range.last}"
end
答案 2 :(得分:-1)
function getDaysInMonth(month, year) {
// Since no month has fewer than 28 days
var date = new Date(year, month, 1);
var days = [];
console.log('month', month, 'date.getMonth()', date.getMonth())
while (date.getMonth() === month) {
days.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return days;
}