java.time
LocalDate d1 = LocalDate.parse("1999-12-01");
Period p2 = Period.ofYears(1);
LocalDate oneYearLater = d1.plus(p2);
System.out.println(oneYearLater);
Output from this snippet is:
2000-12-01
Sorry that I cannot write Scala code. I trust you to translate from Java.
Provided that you are based on at least Java 8 you don’t need an external library. For Java 6 and 7 use the same code, only add the ThreeTen Backport library to your project and import from the org.threeten.bp
package. For Java 5 Joda-Time is the good solution, see the other answer.
Both java.time and the ThreeTen Backport were developed by the same folks that developed Joda-Time and drew heavily on the good (and the few poor) experiences from there. Joda-Time is now in maintenance mode. The Joda-Time home page says: “Note that Joda-Time is considered to be a largely “finished” project. No major enhancements are planned. If using Java SE 8, please migrate to java.time
(JSR-310).”
Links