Skip to content

Instantly share code, notes, and snippets.

@julianpoy
Created April 18, 2018 16:52
Show Gist options
  • Save julianpoy/4b012c211eec5b616d8e2609e9ad786c to your computer and use it in GitHub Desktop.
Save julianpoy/4b012c211eec5b616d8e2609e9ad786c to your computer and use it in GitHub Desktop.
Build a month
var month = []
var fullyear = (new Date()).getFullYear(); // The year you want to start with
var fullmonth = (new Date()).getMonth(); // The month you want (0-11)
var currentDate = new Date(fullyear, fullmonth, 1);
var currentDay = new Date((new Date()).getFullYear(), (new Date()).getMonth(), 1).getDate();
var lastDay = new Date((new Date()).getFullYear(), (new Date()).getMonth() + 1, 0).getDate();
while (currentDay <= lastDay) {
var week = [];
for (var i = currentDate.getDay(); i < 7; i++) {
week[i] = currentDay;
currentDay++;
currentDate = new Date(fullyear, fullmonth, currentDay);
}
month.push(week)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment