How to reduce one month from current date and want to sore in java.util.Date
variable im using this code but it's shows error in 2nd line
java.util.Date da = new Date(); da.add(Calendar.MONTH, -1); //error
How to store this date in java.util.Date
variable?
DateTime yesterday = new DateTime(). minusDays(1);
time. ZonedDateTime zdtMonthLater = zdt. plusMonths( 1 );
The plusMonths() method of LocalDate class in Java is used to add the number of specified months in this LocalDate and return a copy of LocalDate. This method adds the months field in the following steps: Add the months to the month-of-year field. Check if the date after adding months is valid or not.
Use Calendar:
Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); Date result = cal.getTime();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With