posted by 네코냥이 2013. 6. 13. 11:36

출처: BACK TO THE BASIC, JAVA 핵심 요약 노트 : 빠르게 훑어보는 자바 프로그래밍


 public static void main(String args[]) {

      // Calendar 객체를 생성시킨다.

      Calendar calendar = Calendar.getInstance();

      Date toDay = new Date();

      calendar.setTime(toDay);

      // 다양한 형태의 출력 값

      System.out.println("다양한 날짜 정보");

      System.out.println("ERA: " + calendar.get(Calendar.ERA));

      System.out.println("YEAR: " + calendar.get(Calendar.YEAR));

      System.out.println("MONTH: " + calendar.get(Calendar.MONTH));

      System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));

      System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));

      System.out.println("DATE: " + calendar.get(Calendar.DATE));

      System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));

      System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));

      System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));

      System.out.println("DAY_OF_WEEK_IN_MONTH: "+ calendar.get(Calendar.DAY_OF_ 

         WEEK_IN_MONTH));

      System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));

      System.out.println("HOUR: " + calendar.get(Calendar.HOUR));

      System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));

      System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));

      System.out.println("SECOND: " + calendar.get(Calendar.SECOND));

      System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));

      System.out.println("ZONE_OFFSET: "+ (calendar.get(Calendar.ZONE_OFFSET) 

         /(60*60*1000)));

      System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) 

         /(60*60*1000)));

      // Calendar 객체의 시간을 변경한다.

      calendar.clear(Calendar.HOUR_OF_DAY); 61 2부  Java SE 플랫폼

      calendar.set(Calendar.HOUR, 3);

      System.out.println();

      System.out.println("시간을 변경합니다.");

      System.out.println("ERA: " + calendar.get(Calendar.ERA));

      System.out.println("YEAR: " + calendar.get(Calendar.YEAR));

      System.out.println("MONTH: " + calendar.get(Calendar.MONTH));

      System.out.println("WEEK_OF_YEAR: " + calendar.get

         (Calendar.WEEK_OF_YEAR));

      System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_

         OF_MONTH));

      System.out.println("DATE: " + calendar.get(Calendar.DATE));

      System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_

         MONTH));

      System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_

         YEAR));

      System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_

         WEEK));

      System.out.println("DAY_OF_WEEK_IN_MONTH: "  + 

         calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));

      System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));

      System.out.println("HOUR: " + calendar.get(Calendar.HOUR));

      System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));

      System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));

      System.out.println("SECOND: " + calendar.get(Calendar.SECOND));

      System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));

      System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_

         OFFSET)/(60*60*1000))); // in hours

      System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_

         OFFSET)/(60*60*1000))); // in hours

   }

}62 2부  Java SE 플랫폼

실행 결과

다양한 날짜 정보

ERA: 1

YEAR: 2013

MONTH: 1

WEEK_OF_YEAR: 8

WEEK_OF_MONTH: 4

DATE: 18

DAY_OF_MONTH: 18

DAY_OF_YEAR: 49

DAY_OF_WEEK: 2

DAY_OF_WEEK_IN_MONTH: 3

AM_PM: 1

HOUR: 2

HOUR_OF_DAY: 14

MINUTE: 34

SECOND: 9

MILLISECOND: 639

ZONE_OFFSET: 9

DST_OFFSET: 0

시간을 변경합니다.

ERA: 1

YEAR: 2013

MONTH: 1

WEEK_OF_YEAR: 8

WEEK_OF_MONTH: 4

DATE: 18

DAY_OF_MONTH: 18

DAY_OF_YEAR: 49

DAY_OF_WEEK: 263 2부  Java SE 플랫폼

DAY_OF_WEEK_IN_MONTH: 3

AM_PM: 1

HOUR: 3

HOUR_OF_DAY: 15

MINUTE: 34

SECOND: 9

MILLISECOND: 639

ZONE_OFFSET: 9

DST_OFFSET: 0