Java Data Type How to - Get year value from Date


We would like to know how to get year value from Date.


import java.util.Calendar;
import java.util.Date;
/*w  w  w .  j  a  v a2  s  . co m*/
public class Main {
  public static void main(String[] argv) {
    System.out.println(getYear(new Date()));

  public static Integer getYear(Date date) {
    if (date == null)
      return 0;
    Calendar cal = Calendar.getInstance();
    return cal.get(Calendar.YEAR);


The code above generates the following result.