In versions of Java prior to 1.1 it was standard to use the Date class:
Date now = new Date(); // Gets the current date and time
int year = now.getYear(); // Returns the # of years since 1900
However, in newer versions of Java, much of the Date
class has been deprecated (specifically the getYear
method). It is now more standard to use the Calendar class:
Calendar now = Calendar.getInstance(); // Gets the current date and time
int year = now.get(Calendar.YEAR); // The current year