Gnaniyar Zubair Gnaniyar Zubair - 1 year ago 76
Java Question

Find out Last 30 Days, 60 Days and 90 Days in java

How to get last 30 / 60 / 90 days records from given date in java?

I have some records with receivedDate. I want to fetch the records for last 30 or 60 or 90 days from received Date. How to resolve it?

Answer Source

Use java.util.Calendar.

Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_MONTH, -30);
Date today30 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, -60);
Date today60 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, -90);
Date today90 = cal.getTime();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download