import java.util.Calendar;
public class CalendarDemo {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();//日历的实例化,实现的是Calendar子类的方法
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day =cal.get(Calendar.DAY_OF_MONTH);
int hour =cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
System.out.println(year+"-"+(month+1)+"-"+day+" "+hour+":"+minute+":"+second);
}
}
这是一个相对简单的Calendar小例子 |
|