Adds a number of months to a date returning a new object. The original Date is unchanged. The amount to add, may be negative, so you can go 3 months back.
You want today - 3 Month formatted as dd MMMM yyyy
SimpleDateFormat format = new SimpleDateFormat("dd MMMM yyyy");
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.MONTH, -3);
Date d = c.getTime();
String res = format.format(d);
System.out.println(res);
will return the date X months in the past. Similarily, here's a function that returns the date X days in the past.
You can use Apache Commons Lang3 DateUtils addMonths function.
Adds a number of months to a date returning a new object. The original Date is unchanged. The amount to add, may be negative, so you can go 3 months back.
The Date class itself isn't enough (+: You've got to use the Calendar class here
Something along these lines
p.s. the snippet above is not tested to be compilable.
You can use
Hope this helps
Ok with java.sql.Date (subclass of java.util.Date) and JDK's 8 LocalDate help you can do it in one line ;)
You want today - 3 Month formatted as dd MMMM yyyy
So this code can do the job ;)