Java Date to Year getYear(Date date)

Here you can find the source of getYear(Date date)

Description

get Year

License

LGPL

Declaration

public static int getYear(Date date) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int getYear(Date date) {
        return getField(date, Calendar.YEAR);
    }/* w ww. j av  a  2 s .  co m*/

    public static int getField(Date date, int field) {
        int result = -1;
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            result = calendar.get(field);
        }
        return result;
    }
}

Related

  1. getYear(Date d)
  2. getYear(Date d)
  3. getYear(Date d)
  4. getYear(Date date)
  5. getYear(Date date)
  6. getYear(Date date)
  7. getYear(Date date)
  8. getYear(Date date)
  9. getYear(Date date)