Closed liushuangls closed 6 years ago
某个年份的2月有29号则为闰年
function isLeapYear(year) { // 如果year年2月没有29则自动进一变为3月1日 var date = new Date(year, 1, 29) return date.getDate() === 29 } isLeapYear(2000) // true isLeapYear(2001) // false
下个月第0天就是这个月最后一天。
function monthDay(year, month) { var date = new Date(year, month, 0) return date.getDate() } monthDay(2017, 2) // 28 monthDay(2017, 12) // 31
路过~
获取天数还有另外一种思路,下个月的第0天就是这个月的最后一天。
function monthDay(year, month) { var date = new Date(year, month, 0) return date.getDate() }
@n0ruSh 谢谢指教~
判断闰年:
某个年份的2月有29号则为闰年
获取天数:
下个月第0天就是这个月最后一天。