Java Date After dateAfter(Date date, int years, int months)

Here you can find the source of dateAfter(Date date, int years, int months)

Description

date After

License

Open Source License

Declaration

public static Date dateAfter(Date date, int years, int months) 

Method Source Code

//package com.java2s;
/**//from   w w  w .  j  a va  2 s .com
 * Copyright (c) 2014-2015 by Wen Yu.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Any modifications to this file must keep this entire header intact.
 */

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

public class Main {
    public static Date dateAfter(Date date, int years, int months) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, years);
        calendar.add(Calendar.MONTH, months);

        return calendar.getTime();
    }

    public static Date dateAfter(Date date, int years, int months, int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, years);
        calendar.add(Calendar.MONTH, months);
        calendar.add(Calendar.DAY_OF_MONTH, days);

        return calendar.getTime();
    }

    public static Date dateAfter(Date date, int years, int months, int days, int hours, int minutes, int seconds,
            int millisecs) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, years);
        calendar.add(Calendar.MONTH, months);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        calendar.add(Calendar.HOUR, hours);
        calendar.add(Calendar.MINUTE, minutes);
        calendar.add(Calendar.SECOND, seconds);
        calendar.add(Calendar.MILLISECOND, millisecs);

        return calendar.getTime();
    }
}

Related

  1. after(Date point, Date when)
  2. afterDay(final Date date1, final Date date2)
  3. afterMonth(Date dateTime)
  4. afterOneDay(Date depdt)
  5. dateAfter(Date origDate, int amount, int timeUnit)
  6. dateAfterNMonths(Date dt, int n)
  7. daysAfter(Date dateInst, int numDays)
  8. getAfter(Date comparedDate, int cursor, String unit)