Java Day Add addDays(String startDate, int amount)

Here you can find the source of addDays(String startDate, int amount)

Description

add Days

License

Apache License

Declaration

public static String addDays(String startDate, int amount) throws Exception 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String addDays(String startDate, int amount) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(startDate));
        cal.add(Calendar.DAY_OF_MONTH, amount);
        long mills = cal.getTimeInMillis();
        Date date = new Date(mills);
        return sdf.format(date);
    }//from  w w w .  j  a  va2 s.  c  o  m

    public static String addDays(int amount) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, amount);
        long mills = cal.getTimeInMillis();
        Date date = new Date(mills);
        return sdf.format(date);
    }
}

Related

  1. AddDays(long initialDateMilliSeconds, int dayNumber)
  2. addDays(String dateStr, int days)
  3. addDays(String dateStr, int nDays, String inputDateFormat, String outputDateFormat)
  4. addDays(String s, int day)
  5. addDays(String src, int day, String format)
  6. addDays2Date(Date d, int days)
  7. addDays2Date(String str, int days)
  8. addDaysByFormatter(int days, String dateFormat)
  9. addDaysDate(final java.util.Date date1, final int nbdays)