Java Utililty Methods Date Add

List of utility methods to do Date Add

Description

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

Method

Dateadd(Date date, long minutes)
add
if (date == null) {
    throw new IllegalArgumentException();
return addMinutes(date, minutes);
Dateadd(Date eredeti, int mihez, int mennyit)
add
if (eredeti == null) {
    return null;
Calendar cal = new GregorianCalendar();
cal.setTime(eredeti);
cal.add(mihez, mennyit);
return cal.getTime();
Dateadd(Date when, int amount, int field)
Add an offset to a particular day
Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.setTime(when);
calendar.add(field, amount);
return calendar.getTime();
Dateadd(int datePart, int detal, Date date)
add
Calendar c = Calendar.getInstance();
if (date != null)
    c.setTime(date);
c.add(datePart, detal);
return c.getTime();
Dateadd(int field, int value, Date fromDate)
add
fromDate = (fromDate == null) ? new Date() : fromDate;
Calendar cal = Calendar.getInstance();
cal.setTime(fromDate);
cal.add(field, value);
return cal.getTime();
longadd(long date, int field, int amount)
add
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(new Date(date));
cal.add(field, amount);
return cal.getTime().getTime();
Dateadd30Minutes(Date date)
add Minutes
Calendar currentDate = Calendar.getInstance();
currentDate.setTime(date);
int hour = currentDate.get(Calendar.HOUR_OF_DAY);
int minute = currentDate.get(Calendar.MINUTE);
int addHour = (minute + 30) / 60;
minute = (minute + 30) % 60;
hour = hour + addHour;
currentDate.set(Calendar.HOUR_OF_DAY, hour);
...
java.util.DateaddCertainTime(java.util.Date date, double hours)
add Certain Time
int s = (int) (hours * 60 * 60);
int hour = s / 3600;
int min = (s - hour * 3600) / 60;
int sec = s - hour * 3600 - min * 60;
java.util.Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, hour);
cal.add(Calendar.MINUTE, min);
...
StringaddDate(Date date, int add)
add Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, add);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(calendar.getTime());
DateaddDate(Date date, int amount, int type)
add Date
cal.setTime(date);
switch (type) {
case Calendar.DATE:
    cal.add(Calendar.DATE, amount);
return cal.getTime();