private static int getCarAgeByLicense(String theregistrationtime) {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
int carDate = Integer.parseInt(theregistrationtime.substring(0, 4));
int carMonth = Integer.parseInt(theregistrationtime.substring(6, 7));
int nowDate = Integer.parseInt(format.format(date).substring(0, 4));
int nowMonth = Integer.parseInt(format.format(date).substring(5, 6));
if (carDate < nowDate) {
int carAge = nowDate - carDate;
if (carMonth < nowMonth) {
carAge++;
}
return carAge;
} else {
return 1;
}
}
参数为 2018-07-23 这样格式的 返回为年份 最少为一年