Calender

염지은·2021년 12월 12일
0

java

목록 보기
35/45

< Calenadr >

  • 날짜에 대한 정보를 갖는 클래스
  • 추상클래스이므로 객체를 생성할 수 없다.
  • public static Calendar getInstance() 메소드를 사용해서
    현재 날짜와 시간에 대한 정보를 갖는 객체를 얻어와 사용할 수 있다.
    Calendar c=Calendar.getInstance();
  • public int get(int field) : 특정 필드값(년도/월/일/시/분,,,)을 얻어옴
    public class Test02_Calendar {
    	public static void main(String[] args) {
    		Calendar c=Calendar.getInstance();
    		System.out.println(c);
    		//c.set(2020, 0,1);//2020년 1월 1일로 설정
    		c.set(Calendar.DAY_OF_MONTH,20); //특정 필드값 변경 -> 날짜를 20일로 설정
    		c.add(Calendar.DAY_OF_WEEK,20);//날짜에 20일 더하기
    		System.out.println(c);
    		int y=c.get(Calendar.YEAR);
    		int m=c.get(Calendar.MONTH) + 1;
    		int d=c.get(Calendar.DAY_OF_MONTH);
    		System.out.println( y+"년" + m +"월" + d +"일");
    	}
    }

0개의 댓글