VOOZH about

URL: https://www.geeksforgeeks.org/java/year-plusyears-method-in-java-with-examples/

⇱ Year plusYears() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Year plusYears() Method in Java with Examples

Last Updated : 16 Jan, 2019
plusYears() method of the Year class used to a copy of this Year after adding the specified number of years to this year. This instance is immutable and unaffected by this method call. Syntax:
public Year plusYears(long yearsToadd)
Parameters: This method accepts yearsToadd as parameter which is the years to add, may be negative. Return value: This method returns Year based on this year with the years added. Exception: This method throws following Exceptions:
  • DateTimeException - if the result exceeds the supported range.
Below programs illustrate the plusYears() method: Program 1:
Output:
Year :2019
After addition year: 2039
Program 2:
Output:
Year :2019
After addition year: 3219
References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#plusYears(long)
Comment