1、java.util.Calendar是一个抽象类,通过getInstance()静态方法获取一个Calender对象,默认当前时间
2、用Calendar获取年、月、日、时间等信息
package time;
import java.util.Calendar;
public class dateA {
public static void main(String[] args){
Calendar c=Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1; // 0代表 1月
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println("当前时间:"+year +"-"+month +"-" +day +"-" +hour +"-" +minute +"-" +second);
}
}