The list of methods to do Timestamp are organized into topic(s).
Timestamp
add(Timestamp ts, int field, int amount) add
Calendar cal = Calendar.getInstance();
cal.setTime(ts);
cal.add(field, amount);
Timestamp ts2 = new Timestamp(cal.getTime().getTime());
return ts2;
Timestamp
addDate(Timestamp date, String type, int into) add Date
GregorianCalendar grc = new GregorianCalendar();
grc.setTime(new java.util.Date(date.getTime()));
if (type.equals("D")) {
grc.add(GregorianCalendar.DATE, into);
} else if (type.equals("M")) {
grc.add(GregorianCalendar.MONTH, into);
} else if (type.equals("Y")) {
grc.add(GregorianCalendar.YEAR, into);
...
Timestamp
addDays(Timestamp date, int days) add Days
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, days);
return new Timestamp(cal.getTime().getTime());
Timestamp
addDays(Timestamp day, int offset) Return Day + offset (truncates)
if (day == null)
day = new Timestamp(System.currentTimeMillis());
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
...
Timestamp
addDaysToTimestamp(Timestamp timestamp, int numDays) Adds the specified number of Days to the specified Date object To subtract the specified number of Days to the specified Date object, juz use a negative number Example: DateUtil.addDaysToDate(date, -5) == subtracting 5 days from the specified date.
if (timestamp == null) {
return null;
Calendar c = Calendar.getInstance();
c.setTime(timestamp);
c.add(Calendar.DATE, numDays);
return new Timestamp(c.getTimeInMillis());
Timestamp
addHours(Timestamp date, int numOfHours) add Hours
Long milliSecInAnHour = new Long(60 * 60 * 1000);
Timestamp newTS = new Timestamp(date.getTime());
long milliSecToAdd = milliSecInAnHour * numOfHours;
long newTimeMilliSec = newTS.getTime();
newTS.setTime(newTimeMilliSec + milliSecToAdd);
return newTS;
Timestamp
addMilli(Timestamp nowDate, int period) addMilli.
Calendar calendar = Calendar.getInstance();
calendar.setTime(nowDate);
calendar.add(Calendar.MILLISECOND, period);
Timestamp stopTerm = date2Timestamp(calendar.getTime());
return stopTerm;