Skip to content

Instantly share code, notes, and snippets.

@redblue9771
Created July 12, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redblue9771/c710691f9141431c9320720020618ed9 to your computer and use it in GitHub Desktop.
Save redblue9771/c710691f9141431c9320720020618ed9 to your computer and use it in GitHub Desktop.
JavaScript 中一些时间功能的实现 - 检查平润年,返回正确月份的天数
/**
* 检查平润年,返回正确月份的天数
* @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