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:
// Java program to demonstrate // Year.minusYears() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create a Year object Year year = Year.of(2019); // print instance System.out.println("Year :" + year); // apply minusYears method Year value = year.minusYears(20); // print result System.out.println("After subtraction year: " + value); } } |
Year :2019 After subtraction year: 1999
Program 2:
// Java program to demonstrate // Year.minusYears() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create a Year object Year year = Year.of(2019); // print instance System.out.println("Year :" + year); // apply minusYears method Year value = year.minusYears(1200); // print result System.out.println("After subtraction year: " + value); } } |
Year :2019 After subtraction year: 819
References: https://docs.oracle.com/javase/10/docs/api/java/time/Year.html#minusYears(long)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Period minusYears() method in Java with Examples
- LocalDate minusYears() method in Java with Examples
- OffsetDateTime minusYears() method in Java with examples
- ZonedDateTime minusYears() method in Java with Examples
- YearMonth minusYears() in Java with Examples
- Year now() method in Java with examples
- Year of() method in Java with Examples
- Year from() Method in Java with Examples
- Year get() method in Java with Examples
- Year until() Method in Java with Examples
- Year with() Method in Java with Examples
- Year compareTo() method in Java with Examples
- Year isLeap() method in Java with Examples
- Year isBefore() method in Java with Examples
- Year isAfter() method in Java with Examples
- Year plusYears() Method in Java with Examples
- Year hashCode() method in Java with Examples
- Year getValue() method in Java with Examples
- Year length() method in Java with Examples
- Year plus(TemporalAmount) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

