Java Date Add dateAdd(Date date, int days)

Here you can find the source of dateAdd(Date date, int days)

Description

date Add

License

Apache License

Declaration

public static String dateAdd(Date date, int days) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static String dateAdd(Date date, int days) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String toDate = dateFormat.format(new Date());
        return dateAdd(toDate, days);
    }//  w ww.  j  a v a2 s.com

    public static String dateAdd(String date, int days) {
        Calendar cal = Calendar.getInstance();
        int year = 0, month = 0, day = 0;
        try {
            year = Integer.parseInt(date.substring(0, 4));
            month = Integer.parseInt(date.substring(4, 6));
            day = Integer.parseInt(date.substring(6, 8));
        } catch (Exception e) {
        }
        cal.set(year, month - 1, day + days);
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
        return sf.format(cal.getTime());
    }
}

Related

  1. addDays(int count, Calendar timestamp)
  2. addDaysToCurrentDate(Integer dayIncrement)
  3. addInteger(Date date, int dateType, int amount)
  4. addSeconds(Date date1, long secs)
  5. dateAdd(Date date, int days)
  6. dateAdd(Date date, int field, int amount)
  7. dateAdd(Date date, int type, int num)
  8. dateAdd(Date date, int val)
  9. dateAdd(final Date baseDateTime, int daysToAdd, boolean chopTime)