public static String dateAddYear(String date,String oriDateFormat,String targetDateFormat,int n) {
if (StringUtils.isBlank(date) || StringUtils.isBlank(oriDateFormat) ||StringUtils.isBlank(targetDateFormat)) {
return "";
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(oriDateFormat);
Date dateObj = null;
try {
dateObj = simpleDateFormat.parse(date);
} catch (ParseException e) {
return "";
}
Calendar cal = Calendar.getInstance();
cal.setTime(dateObj);
cal.add(Calendar.YEAR, n);
SimpleDateFormat sdf = new SimpleDateFormat(targetDateFormat);
String dateStr = sdf.format(cal.getTime());
return dateStr;
}
|