Created
February 6, 2019 17:26
-
-
Save cometkim/9b52c68c338bd2b886816c9c07e07508 to your computer and use it in GitHub Desktop.
특정 날짜가 그 달의 몇 번 째 주차인지 계산하기
This file contains hidden or 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
const format = require('date-fns/format') | |
const startOfWeek = require('date-fns/start_of_week') | |
const today = new Date() | |
// 시작일이 포함되는 주의 수요일(3)의 포함 달을 기준으로 주차를 계산 | |
const baseDate = startOfWeek(today, { weekStartsOn: 3 }) | |
const baseMonth = baseDate.getMonth() + 1 | |
const baseDays = baseDate.getDate() + 1 | |
const weekOfMonth = Math.ceil(baseDays / 7) | |
console.log(`${format(today, 'YYYY년 MM월 DD일')}은 ${baseMonth}월 ${weekOfMonth}주차 입니다.`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shorthand: