Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

유령노트

JAVA 해당 일자 일주일 범위 구하기용 본문

JAVA

JAVA 해당 일자 일주일 범위 구하기용

유령손 2019. 2. 13. 15:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        //시작일 변경 가능
 
        //범위 검색용 날짜
        String startDt = "2019-02-13";
 
        
        //년, 월, 일 분리
        String[] dateArray = startDt.split("-");
 
        //날짜 표시 포멧 지정
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
 
        //캘린더 생성
        Calendar cal = Calendar.getInstance();
 
        //검색용 날짜 세팅
        cal.set(Integer.parseInt(dateArray[0]), (Integer.parseInt(dateArray[1]) - 1), Integer.parseInt(dateArray[2]));
 
        //일주일의 첫날 선택
        cal.setFirstDayOfWeek(Calendar.MONDAY);
 
 
        //해당 주차 시작일과의 차이 구하기용
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - cal.getFirstDayOfWeek();
 
        //해당 주차의 첫날 세팅
        cal.add(Calendar.DAY_OF_MONTH, - dayOfWeek);
 
        
        //해당 주차의 첫일자
        String stDt = formatter.format(cal.getTime());
 
        //해당 주차의 마지막 세팅
        cal.add(Calendar.DAY_OF_MONTH, 6); 
 
        
        //해당 주차의 마지막일자
        String edDt = formatter.format(cal.getTime());
cs