public class CalendarCal {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat simpleDateformat = new SimpleDateFormat("yy");
String m = simpleDateformat.format(date);
System.out.println("Year:" + m);
int year = Calendar.getInstance().get(Calendar.YEAR) % 100;
System.err.println(year);
}
}
I am able to retrieve the current year from this. How can I get the last (previous) year with help of utility? I don’t want to do a calculation like currentyear - 1 or like that.
Just use
Calendar.addmethod to “add”-1to the year and wrap it in your own utility method:Example:
Prints on my system: