java获取当中系统时间
方法一:
// 获取当前时间
Date day=new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //2020-11-03
String format = df.format(day);
System.out.println(format);
方法二:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = df.format(System.currentTimeMillis());
System.out.println(format);
方法三:
// 获取当前时间
Calendar c = Calendar.getInstance();//可以对每个时间域单独修改 对时间进行加减操作等
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
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 + "/" + date + " " +hour + ":" +minute + ":" + second);