Get a range of the number of days contained by the following months
function getMonthRange(n){
var i = 0
, newDate = new Date()
, year = newDate.getFullYear()
, month = newDate.getMonth()
, result = Array(n)
, date
, isLastMonth
for(;i < n; i++) {
isLastMonth = month == 12
date = new Date(isLastMonth ? ++year : year, isLastMonth ? (month = 1) : ++month, 0)
result[i] = {
days : date.getDate(),
month : month,
year : year
}
}
return result
}
This function returns an Array (with a length of n) that contains for each month :
{
days : number,
month : number,
year : number
}
Written by Matthias Le Brun
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Date
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#