Created
April 18, 2018 16:52
-
-
Save julianpoy/4b012c211eec5b616d8e2609e9ad786c to your computer and use it in GitHub Desktop.
Build a month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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