VOOZH about

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

⇱ Year minusYears() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Year minusYears() method in Java with Examples

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