Android Date Add addYears(Date date, int amount)

Here you can find the source of addYears(Date date, int amount)

Description

add Years

Declaration

public static Timestamp addYears(Date date, int amount) 

Method Source Code

//package com.java2s;

import java.sql.Timestamp;

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

public class Main {
    public static Timestamp addYears(Date date, int amount) {
        return add(date, Calendar.YEAR, amount);
    }//from   ww w . ja va2s  . co  m

    public static Timestamp add(Date date, int calendarField, int amount) {
        if (date == null) {
            throw new IllegalArgumentException("The date must not be null");
        }
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, amount);
        return new Timestamp(c.getTimeInMillis());
    }
}

Related

  1. addSeconds(Date date, int amount)
  2. addSeconds(Date date, int amount)
  3. addWeeks(Date date, int amount)
  4. addWeeks(Date date, int amount)
  5. addYearToDate(Date date, int yearsToBeAdded)
  6. addYears(Date date, int amount)
  7. dateByAddHoursAndMinutes(Date date, int hours, int minutes)
  8. getDateAdd(Date date, int amount)
  9. addDaysToDate(Date date, int days)