I am having quarter end date of last quarter let it be 30-09-20
, the requirement is to find end date of next quarter i.e 31-12-20
. I am using below code to do the same but is it giving wrong output in some scenarios. This solution should be correct for all quarters.
String str = "30-09-20";
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yy");
Date date = format.parse(str);
Date newDate = DateUtils.addMonths(date, 3);
System.out.println(newDate);//Dec 30 - It should be 31 Dec
To answer your question, I think you are looking for this :
Note: don't use the legacy Date library, you tagged your question Java-8 which mean you can use java-time API.
Get last day of current quarter
@deHaar have reason, to get the end date of curent quarter, I would suggest to use :
Get last day of next quarter
To get the last day of the next quarter, then you just can add three months to your date like so :