import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class test53 {public static void main(String[] args){//获取当前时间并且获取当前系统时间创建一个日历实例Calendar cal=Calendar.getInstance();//获取当前时间的年月日int year=cal.get(Calendar.YEAR);int month=cal.get(Calendar.MONTH);int date=cal.get(Calendar.DATE);System.out.println(year);System.out.println(month+1);System.out.println(date);//获取当前对象所需要的date对象Date currentTime =cal.getTime();SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");System.out.println(sdf.format(currentTime));}
}
运行结果