Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add one month to current date in Java?

Tags:

java

java-time

In Java how can I add one month to the current date?

like image 850
kiran Avatar asked Feb 05 '11 06:02

kiran


People also ask

How do you populate the current date in Java?

Code To Get Today's date in any specific FormatgetTime(); String todaysdate = dateFormat. format(date); System. out. println("Today's date : " + todaysdate);

How do you calculate months in Java?

Once you have the LocalDate, you can use Months. monthsBetween() and Years. yearsBetween() method to calcualte the number of months and years between two dates in Java. LocalDate jamesBirthDay = new LocalDate(1955, 5, 19); LocalDate now = new LocalDate(2015, 7, 30); int monthsBetween = Months.

Can we add date in Java?

In Java, we can add a single day or days to the given date or current date using Calendar class.


2 Answers

Calendar cal = Calendar.getInstance();  cal.add(Calendar.MONTH, 1); 
like image 84
Piyush Mattoo Avatar answered Sep 18 '22 14:09

Piyush Mattoo


Java 8

LocalDate futureDate = LocalDate.now().plusMonths(1); 
like image 32
softarn Avatar answered Sep 20 '22 14:09

softarn