220922 해당하는 날짜가 포함되는 주의 시작과 끝/ 월의 시작과 끝을 구하는 코드

Jongleee·2022년 9월 22일
1

TIL

목록 보기
60/576
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setTime(sdf.parse(String.valueOf(DateTime.now())));
//week
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
String startDate = sdf.format(cal.getTime());
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
String endDate = sdf.format(cal.getTime());
makeStatisticByPeriod(memberList, startDate, endDate, "Week");
//month
cal.set(Calendar.DAY_OF_MONTH, 1);
startDate = sdf.format(cal.getTime());
cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH));
endDate = sdf.format(cal.getTime());
makeStatisticByPeriod(memberList, startDate, endDate, "Month");

해당하는 날짜가 포함되는 주의 시작과 끝/ 월의 시작과 끝을 구하는 코드

캘린더를 활용해 시작점을 설정하고 캘린더에서 주와 월의 정보를 얻어서 사용함

0개의 댓글