Java Year nextYears(int diff)

Here you can find the source of nextYears(int diff)

Description

next Years

License

Apache License

Declaration

public static Date nextYears(int diff) 

Method Source Code

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

import java.util.*;

public class Main {

    public static Date nextYears(int diff) {
        return add(new Date(), Calendar.YEAR, diff);
    }//from  ww  w. j a  v  a 2  s  . c  o  m

    public static Date nextYears(Date date, int diff) {
        return add(date, Calendar.YEAR, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(Date date, int field, int diff) {
        Calendar c = getCalendar(date);
        c.add(field, diff);
        return c.getTime();
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(int field, int diff) {
        return add(new Date(), field, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(long millis) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(millis);
        return c;
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
}

Related

  1. daysInYear(int year)
  2. differenceInYears(final Calendar a, final Calendar b)
  3. diffYears(Date day1, Date day2)
  4. IsInLeapYear(Date date1)
  5. isLeapYear(int year)
  6. sameYear(Date date1, Date date2)
  7. yearAndSeason(Date date)