1var date = new Date();
2var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
3var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
4
1var date = new Date();
2var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
3var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
1var lastday = function(y,m){
2return new Date(y, m +1, 0).getDate();
3}
4console.log(lastday(2014,0));
5console.log(lastday(2014,1));
6console.log(lastday(2014,11));
7
8
1var lastday = function(y,m){
2return new Date(y, m +1, 0).getDate();
3}
4console.log(lastday(2014,0));
5console.log(lastday(2014,1));
6console.log(lastday(2014,11));
7
1var d = new Date();
2d.setDate(0); //sets d to the last day of the previous month
3d.setDate(1); //sets d the the first day of that month
4d.setHours(0,0,0,0); //sets d time to midnight
5
6//d now equals the first day of the month before today