Created
July 12, 2019 14:16
-
-
Save redblue9771/c710691f9141431c9320720020618ed9 to your computer and use it in GitHub Desktop.
JavaScript 中一些时间功能的实现 - 检查平润年,返回正确月份的天数
This file contains 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
/** | |
* 检查平润年,返回正确月份的天数 | |
* @param year 年份 | |
* @param month 月份 | |
* @returns {number} 该月正确的天数 | |
*/ | |
function checkTime(year, month) { | |
if (month === 2) return (year % 4 === 0 && year % 100 !== 0 || year % 400) === 0 ? 29 : 28; | |
return '4;6;9;11'.indexOf(month + ';') === -1 ? 31 : 30; | |
} | |
document.write(checkTime(2017,2)); | |
//最终打印出28 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment