Skip to content

Instantly share code, notes, and snippets.

@TehShrike
Last active January 10, 2020 19:43
Show Gist options
  • Save TehShrike/6a27b28160bad1e3ccd98e2ee3ea752c to your computer and use it in GitHub Desktop.
Save TehShrike/6a27b28160bad1e3ccd98e2ee3ea752c to your computer and use it in GitHub Desktop.
daysInMonth.js
// An expansion of https://stackoverflow.com/a/1184359/201789
function daysInMonth (oneIndexedInputMonth, year) {
const zeroIndexedInputMonth = oneIndexedInputMonth - 1
const theNextZeroIndexedMonth = zeroIndexedInputMonth + 1
const theFinalDayOfThePreviousMonth = 0
return new Date(year, theNextZeroIndexedMonth, theFinalDayOfThePreviousMonth).getDate()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment