package api8_Date;
import java.util.Calendar;
public class T2_Calender {
public static void main(String[] args) {
// Calendar객체는 싱글톤이므로 getInstance()로 가져와 사용해야 하며, 모든 값은 상수로 선언되어있음.
Calendar cal = Calendar.getInstance();
System.out.println("년도 : " + cal.get(Calendar.YEAR));
// Calendar객체는 0월부터 계산하므로 +1이 필요하다!!! [월 만 그 렇 다]
System.out.println("월 : " + (cal.get(Calendar.MONTH)+1));
System.out.println("일 : " + cal.get(Calendar.DATE));
System.out.println("시간 : " + cal.get(Calendar.HOUR_OF_DAY));
System.out.println("분: " + cal.get(Calendar.MINUTE));
System.out.println("초: " + cal.get(Calendar.SECOND));
System.out.println("오늘이 몇번째 주: " + cal.get(Calendar.WEEK_OF_YEAR));
// 일월화수목금토 순서임! ex) 일요일 : 1 , 월요일 : 2
System.out.println("오늘이 몇번째 일(이번달): " + cal.get(Calendar.DAY_OF_WEEK));
// 0이면 AM , 1이면 PM
System.out.println(cal.get(Calendar.AM));
System.out.println(cal.get(Calendar.PM));
int amPm = cal.get(Calendar.AM_PM);
String strAmPm = "";
if(amPm == Calendar.AM) strAmPm = "오전";
else strAmPm = "오후";
System.out.println("지금은 "+strAmPm+"입니다.");
int week = cal.get(Calendar.DAY_OF_WEEK);
String strWeek = "";
switch(week) {
case Calendar.MONDAY: strWeek = "월"; break;
case Calendar.TUESDAY : strWeek = "화"; break;
case Calendar.WEDNESDAY : strWeek = "수"; break;
case Calendar.THURSDAY : strWeek = "목"; break;
case Calendar.FRIDAY : strWeek = "금"; break;
case Calendar.SATURDAY : strWeek = "토"; break;
case Calendar.SUNDAY : strWeek = "일"; break;
}
System.out.println("오늘은 " + strWeek + "요일 입니다." );
}
}
첫댓글 좋습니다. 주말에 못다한 공부들~ 많이 많이 채워주세요.. 수고했어요