[java入門]java.util.Calendarクラスの使い方
1.javaコード
import java.util.Calendar;
public class CalendarDemo {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// 計算出力
System.out.println(“年: " + cal.get(Calendar.YEAR));
System.out.println(“月: " + cal.get(Calendar.MONTH));
System.out.println(“日: " + cal.get(Calendar.DATE));
System.out.println(“HOUR: " + cal.get(Calendar.HOUR));
System.out.println(“MINUTE: " + cal.get(Calendar.MINUTE));
System.out.println(“SECOND: " + cal.get(Calendar.SECOND));
System.out.println(“MILLISECOND: " + cal.get(Calendar.MILLISECOND));
System.out.println(“DAY_OF_YEAR: " + cal.get(Calendar.DAY_OF_YEAR));
System.out.println(“DAY_OF_MONTH: " + cal.get(Calendar.DAY_OF_MONTH));
System.out.println(“DAY_OF_WEEK: " + cal.get(Calendar.DAY_OF_WEEK));
System.out.println(“DAY_OF_WEEK_IN_MONTH: " + cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println(“WEEK_OF_YEAR: " + cal.get(Calendar.WEEK_OF_YEAR));
System.out.println(“WEEK_OF_MONTH: " + cal.get(Calendar.WEEK_OF_MONTH));
System.out.println(“AM_PM: " + cal.get(Calendar.AM_PM));
System.out.println(“HOUR_OF_DAY: " + cal.get(Calendar.HOUR_OF_DAY));
System.out.println(“ERA: " + cal.get(Calendar.ERA));
}
}
2.結果
年: 2017
月: 10
日: 3
HOUR: 11
MINUTE: 57
SECOND: 29
MILLISECOND: 988
DAY_OF_YEAR: 307
DAY_OF_MONTH: 3
DAY_OF_WEEK: 6
DAY_OF_WEEK_IN_MONTH: 1
WEEK_OF_YEAR: 44
WEEK_OF_MONTH: 1
AM_PM: 0
HOUR_OF_DAY: 11
ERA: 1