Skip to content

Instantly share code, notes, and snippets.

@adkdev
Created January 14, 2016 07:08
Show Gist options
  • Save adkdev/75e3039325038e55b911 to your computer and use it in GitHub Desktop.
Save adkdev/75e3039325038e55b911 to your computer and use it in GitHub Desktop.
Get number days in specified month
// ref: http://stackoverflow.com/questions/1184334/get-number-days-in-a-specified-month-using-javascript
// ref: http://stackoverflow.com/questions/16353211/check-if-year-is-leap-year-in-javascript
function daysInMonth(year, month) {
var isLeapYeaer = new Date(year, 1, 29).getMonth() == 1;
return [31, (isLeapYeaer ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment