자바스크립트 이번주 월요일, 이번달 1일
본문
const date = new Date()
if (type === 'day') {
regStart = formatDate(date)
regEnd = formatDate(new Date(date.valueOf() + 1000 * 3600 * 24))
console.log(regStart, regEnd)
} else if (type === 'week') { // 이번주 월요일 ~ 일요일
regStart = formatDate(date)
regEnd = formatDate(new Date(date.valueOf() + 1000 * 3600 * 24 * 7))
} else if (type === 'month') { // 이번달 1일 ~ 31일
regStart = formatDate(date)
regEnd = formatDate(new Date(date.valueOf() + 1000 * 3600 * 24 * 31))
}
위 소스는 오늘 기준으로 7일
예) 2017-11-29(목) ~ 2017-12-5(수)
오늘 기준으로 한달
예) 2017-11-29 ~ 2017-12-28
이렇게 되어있는데
제가 원하는 것은 이번주가 속한 월요일
11월 27(월) ~ 12월 3일
이번달의 1일 ~ 31 11월 1일 ~ 11월 31일
이렇게 구하고 싶습니다.
이것 해결 못해서 오전 내내 시간만 날렸네요 ㅠㅠ
답변 3
월요일 구하기
메서드 이용
달구하기
new Date(date.getFullYear(), date.getMonth(), 1))
new Date(date.getFullYear(), date.getMonth() + 1, 0))
자체 해결 완료
답변을 작성하시기 전에 로그인 해주세요.