달력을 표현한 추상 클래스.
지역, 문화, 나라에 따라 역법이 다르기 때문에 구체적인 역볍 계산 로직은 하위 클래스에서 구현하도록 되어있다.
추상 클래스라 new 연산자를 사용해서 인스턴스를 생성할 수 없다.
그래서 static 메소드인 getInstance() 메소드를 이용하여 Calendar 하위 객체를 얻을 수 있다.
Calendar now = Calendar.getInstance();
//다른 시간대의 Calendar 객체를 얻고 싶을 때
TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");
Calendar now = Calendar.getInstance( timeZone );
Calendar 객체를 얻었다면 get() 메소드로 날짜와 시간 정보를 읽을 수 있다.
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH) + 1;
int day = now.get(Calendar.DAY_OF_MONTH);
int week = now.get(Calendar.DAY_OF_WEEK);
int amPm = now.get(Calendar.AM_PM);
int hour = now.get(Calendar.HOUR);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
'old > Java' 카테고리의 다른 글
[스크랩] JSP란? (0) | 2020.11.18 |
---|---|
[스크랩] 서블릿이란? (0) | 2020.11.18 |
java.util.Date / java.text.SimpleDateFormat (0) | 2020.11.16 |
java.lang.Math / java.util.Random (0) | 2020.11.16 |
java.lang.Wrapper (0) | 2020.11.16 |