I am getting inputDate as "2020-09-08T20:06:19-0400" ;I am following below approach to add 90 days to it and final format should be in "yyyy-MM-dd"?
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZ");
Date newInputDate= addDays(inputFormat.parse(inputDate), 90);
System.out.println("newInputDate:"+newInputDate);
//getting newInputDate as Tue Dec 08 05:36:19 IST 2020 so I have to change it to required format i.e."yyyy-MM-dd"
String endDate= dateFormater(newInputDate.toString() , "yyyy-MM-dd" , "E MMM dd HH:mm:ss Z yyyy");
System.out.println("endDate:"+endDate);
private static Date addDays(Date date, int days) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DATE, days);
return cal.getTime();
}
private static String dateFormater(String dateFromJSON, String expectedFormat, String oldFormat) {
SimpleDateFormat dateFormat = new SimpleDateFormat(oldFormat);
Date date = null;
String convertedDate = null;
try {
date = dateFormat.parse(dateFromJSON);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(expectedFormat);
convertedDate = simpleDateFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
writeToLog("dateFormater Exception :" + e.getMessage());
}
return convertedDate;
}