-2

I have an input field, where i can select the date from date picker.Based on this selected value i need to get the 30 days back date.

Thanks in advance.

aaaa
  • 487
  • 4
  • 13
  • 24

1 Answers1

10
Calendar cal = Calendar.getInstance();
cale.add(Calendar.DATE, -30);
System.out.println("Date = " + cal.getTime());
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
  • 1
    FYI, the troublesome old date-time classes such as [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html), [`java.util.Calendar`](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html), and `java.text.SimpleDateFormat` are now [legacy](https://en.wikipedia.org/wiki/Legacy_system), supplanted by the [java.time](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) classes. See [Tutorial by Oracle](https://docs.oracle.com/javase/tutorial/datetime/TOC.html). Solution: `LocalDate.now().minusDays( 30 )` – Basil Bourque Oct 02 '17 at 05:23