Java Date Set setYear(Date date, int year)

Here you can find the source of setYear(Date date, int year)

Description

set Year

License

LGPL

Declaration

public static Date setYear(Date date, int year) 

Method Source Code

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

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

public class Main {
    public static Date setYear(Date date, int year) {
        return setField(date, Calendar.YEAR, year);
    }/*from ww  w.j a  va  2  s .  c  o m*/

    public static Date setField(Date date, int field, int value) {
        Date result = date;
        if (date != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(field, value);
            result = calendar.getTime();
        }
        return result;
    }
}

Related

  1. setTimeZero(Date dt)
  2. setToDayStartTime(Date date)
  3. setToLastDayInMonth(final Date date)
  4. setToMidnight(Date d)
  5. setYear(Date d, int year)
  6. stripTime(Date d)
  7. stripTime(Date date)
  8. stripTime(Date date)
  9. stripTime(Date time)