Get integer value of the current year in Java

karlgrz picture karlgrz · Sep 25, 2008 · Viewed 484.3k times · Source

I need to determine the current year in Java as an integer. I could just use java.util.Date(), but it is deprecated.

Answer

cagcowboy picture cagcowboy · Sep 25, 2008
int year = Calendar.getInstance().get(Calendar.YEAR);

Not sure if this meets with the criteria of not setting up a new Calendar? (Why the opposition to doing so?)