We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
362 - 5 = 357
357 / 7 = 51
function isLeapYear(year) { if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) return true return false } function getDay(date) { const day = new Date(date).getDay() if (day === 0) return 7 return day } function getWeeksByYear(year = new Date().getFullYear()) { const currentYearDays = isLeapYear(year) ? 366 : 365 const beforeDays = 7 - getDay(`${year}-01-01`) + 1 const afterDays = getDay(`${year}-12-31`) const weeks = (currentYearDays - beforeDays - afterDays) / 7 return weeks } getWeeksByYear() // 51 getWeeksByYear(2020) // 51
判断是否是闰年的条件(二者满足其中之一即为闰年):
The text was updated successfully, but these errors were encountered:
No branches or pull requests
思路
362 - 5 = 357
。正常情况 357 这个数计算出来是 7 的倍数。357 / 7 = 51
即为周数。实现
补充
判断是否是闰年的条件(二者满足其中之一即为闰年):
The text was updated successfully, but these errors were encountered: