Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get next year's date

I want to get today's day and a date which is one year after today. For example, if today is 2015-9-18, next year is 2016-9-18.

I would like to use Java LocalDate.

like image 792
Adrian Xie Avatar asked Dec 07 '25 07:12

Adrian Xie


1 Answers

The current date is simply retrieved with:

LocalDate now = LocalDate.now();

Then, you can add one year to this date, using the method plusYears(years):

LocalDate oneYearAfter = now.plusYears(1);

LocalDate contains various methods to ease the task of adding or subtracting a temporal amount (like plusDays, plusMonths; the most general being plus(amount, unit) adding the amount given for the specified unit of time).

like image 89
Tunaki Avatar answered Dec 08 '25 20:12

Tunaki