In this example we will show the method to subtract years in Java.
Source Code
package com.beginner.examples;
import java.util.Calendar;
public class SubtractYears {
public static void main(String[] args){
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.YEAR));
//years subtract 1
c.add(Calendar.YEAR, -1);
System.out.println(c.get(Calendar.YEAR));
}
}
Output:
2020
2019
References
Imported packages in Java documentation: