Period minusYears() method in Java with Examples
The minusYears() method of Period class in Java is used to subtract the specified years from given period. This functions operates only on YEARS and does not affect other two MONTHS and DAYS.
public Period minusYears(long yearsToSubtract)
Parameters: This method accepts a single parameter yearsToSubtract which is the number of year to be subtracted from the period.
Returns Value: This method returns a Period based on provided period in the input subtracting the specified number of years. It must not be null.
Exceptions: It throws an ArithmeticException. This exception is caught if numeric overflow occurs.
Below programs illustrate the above method:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.