Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CongAn/b7d5ee20e1ee7ca689687e56b951b390 to your computer and use it in GitHub Desktop.
Save CongAn/b7d5ee20e1ee7ca689687e56b951b390 to your computer and use it in GitHub Desktop.
const date = moment()
const firstDayOfYear = moment(date.format('YYYY-01-01'))
// 获得第多少周(跨年周算第一周)
const weeks = (
// 获得第多少天
date.diff(firstDayOfYear, 'days') -
// 减去第一周天数
(7 - firstDayOfYear.weekday()) -
// 减去该时间当前周的天数
date.weekday()
) / 7 + 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment