Last active
August 29, 2015 14:06
-
-
Save Alex1990/63e7426fa32826740b05 to your computer and use it in GitHub Desktop.
Get the number of days in a month in javascript.
This file contains hidden or 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
| /** | |
| * Get the number of days in a month in javascript. | |
| * | |
| * Ref: | |
| * http://stackoverflow.com/questions/315760/what-is-the-best-way-to-determine-the-number-of-days-in-a-month-with-javascript | |
| */ | |
| function daysInMonth(year, month) { | |
| var now = new Date; | |
| month = typeof month != undefined ? month | |
| : (typeof year != undefined ? year : now.getMonth() + 1); | |
| year = typeof month != undefined && typeof year != undefined ? year | |
| : now.getFullYear(); | |
| now.setFullYear(year, month, 0); | |
| return now.getDate(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment