Java Utililty Methods Day Add

List of utility methods to do Day Add

Description

The list of methods to do Day Add are organized into topic(s).

Method

Stringadd(int date, int days)
add
try {
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    Calendar cd = Calendar.getInstance();
    cd.setTime(format.parse(String.valueOf(date)));
    cd.add(Calendar.DAY_OF_YEAR, days);
    return format.format(cd.getTime());
} catch (ParseException e) {
    throw new RuntimeException(e);
...
Stringadd(String date, int day)
add
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
long d = df.parse(date).getTime();
long millis = d + ((long) day) * 24 * 3600 * 1000;
return df.format(new Date(millis));
DateaddDate(Date d, long day)
add Date
long time = d.getTime();
day = day * 24 * 60 * 60 * 1000;
time += day;
return new Date(time);
DateaddDate(Date date, int day)
add Date
Calendar calendar = Calendar.getInstance();
long millis = getMillis(date) + day * 24L * 3600L * 1000L;
calendar.setTimeInMillis(millis);
return calendar.getTime();
java.util.DateaddDate(java.util.Date date, int day)
add Date
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTimeInMillis(getMillis(date) + ((long) day) * 24 * 3600 * 1000);
return c.getTime();
StringaddDate(String date, SimpleDateFormat format, int dayCnt)
add Date
Date oldDate = new Date();
long curTimeStamp = 0;
try {
    oldDate = format.parse(date);
} catch (ParseException e) {
    return date;
curTimeStamp = oldDate.getTime();
...
DateaddDate(String str, int field, int dayNum)
add Date
Date date = null;
SimpleDateFormat sdate = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar gc = new GregorianCalendar();
try {
    date = (Date) sdate.parse(str);
    gc.setTime(date);
    gc.add(field, dayNum);
} catch (ParseException e) {
...
DateaddDay(Date d, int amount)
add Day
return add(d, Calendar.DATE, amount);
DateaddDay(Date date, int day)
add Day
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DAY_OF_MONTH, day);
return c.getTime();
DateaddDay(Date date, int day)
add Day
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, day);
return cal.getTime();