Java处理Date的过期函数getYear()等

Date date = new Date();
// date.getYear(); //已过期

Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);

System.out.println(year + "-" + month + "-" + day);

你可能感兴趣的:(Java代码)