void set(int field, int value)
void set(int year, int month, int date)
void set(int year, int month, int date, int hourOfDay, int minute)
void set(int year, int month, int date, int hourOfDay, int minute, int second)
- 날짜 지정 방법. (※ MONTH는 0부터 시작)
Calendar date1 = Calendar.getInstance();
date1.set(2017, 7, 15);
System.out.println("date1은" + toString(date1)
Calendar time1 = Calendar.getInstance();
time1.set(Calendar.HOUR_OF_DAY, 10);
time1.set(Calendar.MINUTE, 20);
time1.set(Calendar.SECOND, 30);
public static void main(String[] args) {
final String[] DAY_OF_WEEK = {"","일","월","화","수","목","금","토"};
Calendar date1 = Calendar.getInstance();
Calendar date2 = Calendar.getInstance();
date1.set(2019, 3, 29);
System.out.println("date1은" + toString(date1)
+ DAY_OF_WEEK[date1.get(Calendar.DAY_OF_WEEK)] + "요일이고,");
System.out.println("오늘(date2)은" + toString(date2)
+ DAY_OF_WEEK[date2.get(Calendar.DAY_OF_WEEK)]+"요일입니다.");
long difference =
(date2.getTimeInMillis() - date1.getTimeInMillis())/1000;
System.out.println("그 날(date1)부터 지금(date2)까지"
+ difference + "초가 지났습니다.");
System.out.println("일(day)로 계산하면"
+difference/(24*60*60)+"일입니다.");
}
public static String toString(Calendar date) {
return date.get(Calendar.YEAR)+"년"+(date.get(Calendar.MONTH) + 1)
+ "월" + date.get(Calendar.DATE) + "일";
}