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

DateaddDays(final Date date, final int days)
Returns a date a given number of days after the requested date
final GregorianCalendar c = gregorianCalendarThreadLocal.get();
c.setTime(date);
c.add(Calendar.DATE, days);
return c.getTime();
StringaddDays(int days)
add Days
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
cal.add(Calendar.DATE, days);
return yyyyMMdd.format(cal.getTime());
DateaddDays(int days, Date date)
add Days
Calendar calendar = newCalendar(date);
calendar.add(Calendar.DAY_OF_MONTH, days);
return calendar.getTime();
IntegeraddDays(Integer dateAsInt, Integer daysToAdd)
addDays: returns the integer as date {talendTypes} String {Category} TimestampUtil {param} Integer(dateAsInt) dateAsInt : {param} Integer(daysToAdd) daysToAdd : {example} addDays(dateAsInt, daysToAdd) # 20150403
if (dateAsInt != null) {
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.set(java.util.Calendar.MINUTE, 0);
    c.set(java.util.Calendar.SECOND, 0);
    c.set(java.util.Calendar.MILLISECOND, 0);
    c.set(java.util.Calendar.HOUR_OF_DAY, 0);
    int year = dateAsInt / 10000;
    int monthDay = (dateAsInt - (year * 10000));
...
DateaddDays(java.util.Date value, final int days)
add Days
final Calendar cal = Calendar.getInstance();
cal.setTime(value);
cal.add(Calendar.DATE, days);
final Date adjusted = cal.getTime();
return adjusted;
longAddDays(long initialDateMilliSeconds, int dayNumber)
Add Days
return initialDateMilliSeconds + dayNumber * 24 * 3600 * 1000;
DateaddDays(String dateStr, int days)
add Days
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    Date date = sdf.parse(dateStr);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.DATE, 15);
    return cal.getTime();
} catch (Exception e) {
...
StringaddDays(String dateStr, int nDays, String inputDateFormat, String outputDateFormat)
add days to a given date
try {
    DateFormat inputFormatter = new SimpleDateFormat(inputDateFormat);
    DateFormat outputFormatter = inputDateFormat.equals(outputDateFormat) ? inputFormatter
            : new SimpleDateFormat(outputDateFormat);
    Date date = (Date) inputFormatter.parse(dateStr);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DATE, nDays);
...
StringaddDays(String s, int day)
add Days
return addDays(s, day, "yyyyMMdd");
StringaddDays(String src, int day, String format)
add Days
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
Calendar calendar = Calendar.getInstance(Locale.UK);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
Date date = null;
try {
    date = formatter.parse(src);
} catch (ParseException e) {
...