List

목요일, 12월 03, 2015

java로 주간 날짜 구하기


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
39
40
41
42
43
44
45
     Calendar calendar = Calendar.getInstance();
     SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 
     int iDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1
     System.out.println("아이데이오브위크 : "+iDayOfWeek);
     Date dt = new Date();  
i값이 1이면 다음주
i값이 -1이면 저번주.
i값이 0이면 이번주
     long unix_time = dt.getTime()/1000+86400*7*I;//7이 일주일 뒤
     long startDate = unix_time - iDayOfWeek*86400;
     long date02 = unix_time - (iDayOfWeek-1)*86400;
     long date03 = unix_time - (iDayOfWeek-2)*86400;
     long date04 = unix_time - (iDayOfWeek-3)*86400;
     long date05 = unix_time - (iDayOfWeek-4)*86400;
     long date06 = unix_time - (iDayOfWeek-5)*86400;
     
     System.out.println("유닉스 타임 : "+unix_time);
     System.out.println("스타트 데이트? : "+startDate);
     long endDate = unix_time;
     
     for(int y=iDayOfWeek; y < 6; y++) {
      endDate = endDate+86400;
     }
     
     Date dt2 = new Date(startDate*1000);
     Date dt4 = new Date(date02*1000);
     Date dt5 = new Date(date03*1000);
     Date dt6 = new Date(date04*1000);
     Date dt7 = new Date(date05*1000);
     Date dt8 = new Date(date06*1000);
     Date dt3 = new Date(endDate*1000);
     
     String sStart = sdf.format(dt2);
     String day01=sdf.format(dt4);
     String day02=sdf.format(dt5);
     String day03=sdf.format(dt6);
     String day04=sdf.format(dt7);
     String day05=sdf.format(dt8);
     String sEnd = sdf.format(dt3);
     
     System.out.println(sStart);
     System.out.println(day01);
     System.out.println(day02);
     System.out.println(day03);
     System.out.println(day04);
     System.out.println(day05);
     System.out.println("종료일 : "+sEnd);
cs

--출력 화면 --

Calendar.DAY_OF_WEEK...5
5
목요일
아이데이오브위크 : 4
유닉스 타임 : 1449720130
스타트 데이트? : 1449374530
20151206
20151207
20151208
20151209
20151210
20151211
종료일 : 20151212


댓글 없음:

댓글 쓰기