StratoSphere Stream

프로그래밍/JAVA +1


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
46
47
48
49
50
51
52
53
54
55
56
57
  Date date = new Date();
    long dateLongTime = date.getTime();
    //Date함수를 사용한 long time 구하기
    System.out.println(dateLongTime);
 
    //System을 사용한 long time 구하기
    long dateLongTime2 = System.currentTimeMillis();
    System.out.println(dateLongTime2);
 
    //Calander함수를 이용한
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",Locale.KOREA);
    // 날자를 set 하는 방법 (달은 0에서 시작한다)
    cal.set(2000,0,1);
    //SimpleDateFormat을 사용한 날짜 String
    System.out.println("현재날자 : " +sdf.format(cal.getTime()));
 
    //년월일 구하는 방법
    System.out.println("년 : " +cal.get(Calendar.YEAR));
    System.out.println("월 : " +cal.get(Calendar.MONTH));
    System.out.println("일 : " +cal.get(Calendar.DATE));
    System.out.println("요일여부 : " +cal.get(Calendar.DAY_OF_WEEK)); //1: 일요일 , 2: 월요일.. 7: 토요일
    System.out.println("WEEK_OF_YEAR : " +cal.get(Calendar.WEEK_OF_YEAR));// 몇째주 주인가?
    //2000년의 2월의 마지막 날은? => 29일
    System.out.println ("월의 마지막 일자 : " + cal.getActualMaximum ( Calendar.DATE ) );
 
    //1년에 전체 요일과 일요일과 토요일이 그리고 토요일과일요일을은 몇개?
    int allDay = 0;
    int allDayHoliday = 0;
    int allDaySun = 0;
    int allDaySat = 0;
 
    for(int i = 0; i< 12 ; i++){
      cal.set(2000,i,1); //초기 날짜 받음
      int x = cal.getActualMaximum ( Calendar.DATE ); //달의 마지막 날자를 다름 for에서 length로 수정
 
      for(int j = 1; j<= x ; j++){
        cal.set(2000,i,j); //day를 수정해줌
 
        int temp = cal.get(Calendar.DAY_OF_WEEK);
        System.out.println("temp: " + temp);
        if(temp == 1 ){
          allDayHoliday++;
          allDaySun++;
        }
        if(temp == 7 ){
          allDayHoliday++;
          allDaySat++;
        }
        allDay++;
      }
 
    }
    System.out.println("전체: " + allDay); //2000년은 윤년이 있어서 366일이다.
    System.out.println("전체토일: " + allDayHoliday); // 106
    System.out.println("일요일: " + allDaySun); //53
    System.out.println("토요일: " + allDaySat); // 53
cs


'프로그래밍 > JAVA' 카테고리의 다른 글

[자바] Date 함수와 Calender 함수  (0) 2018.10.15

Comment : 0