Java Date to Year getYearOfDate(Date date)

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

Description

get Year Of Date

License

Open Source License

Declaration

public final static int getYearOfDate(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {

    public final static int getYearOfDate(Date date) {
        return getFieldValueByDate(date, Calendar.YEAR);
    }/*  w  w w  . ja v  a2 s .c  o  m*/

    /**
     * get field value by date and the field, like get the year of a date
     *
     * @param date
     * @param field
     * @return
     */
    public final static int getFieldValueByDate(Date date, int field) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(field);
    }
}

Related

  1. getYearMonthDay(Date date)
  2. getYearMonthDay(Date date)
  3. getYearMonthInt(Date date)
  4. getYearMonthOfLastMon(Date date)
  5. getYearNumber(Date date)
  6. getYearOfThisYear(Date currentdate)
  7. getYearOnlyDate(String year)
  8. getYears(java.util.Date date0, java.util.Date date1)
  9. getYearStart(Date date)