function daysInMonth (month, year) { // Use 1 for January, 2 for February, etc. return new Date(year, month, 0).getDate();}console.log(daysInMonth(2, 1999)); // February in a non-leap year.console.log(daysInMonth(2, 2000)); // February in a leap year.
第0天是上个月的最后一天。因为month构造函数是基于0的,所以效果很好。有点hack,但这基本上就是您减去32的结果。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)