Java Date Add dateAddDays(Date time, int days, String dateFormat)

Here you can find the source of dateAddDays(Date time, int days, String dateFormat)

Description

date Add Days

License

Open Source License

Declaration

public static String dateAddDays(Date time, int days, String dateFormat) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String dateAddDays(Date time, int days, String dateFormat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        long timeLong = time.getTime() / 1000 + 60l * 60 * 24 * days;
        time.setTime(timeLong * 1000);/*from w ww .j  a  va2 s  . c o m*/
        String timeStr = sdf.format(time);
        return timeStr;
    }

    public static String dateAddDays(Date time, int days, SimpleDateFormat dateFormat) {
        long timeLong = time.getTime() / 1000 + 60l * 60 * 24 * days;
        time.setTime(timeLong * 1000);
        String timeStr = dateFormat.format(time);
        return timeStr;
    }
}

Related

  1. DateAdd3Days(String _date)
  2. dateAddDay(Date date, int day)
  3. DateAddDays(Date _date, int days)
  4. dateAddDays(Date date, int days)
  5. dateAddDays(Date date, int days)
  6. dateAddHours(Date time, int hours, SimpleDateFormat dateFormat)
  7. dateAddMinutes(Date date, int minutes)
  8. dateAddMM(Date date, int i)
  9. dateAddMonths(Date date, int addMonths)