Java Utililty Methods Timestamp

List of utility methods to do Timestamp

Description

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

Method

java.sql.TimestampaddMonth(java.sql.Timestamp src, int val)
addMonth - Returns the timestamp after adding certain amount of Month.
java.util.Calendar tmpCal = timestampToCalendar(src);
if (tmpCal == null) {
    return (null);
tmpCal.add(java.util.Calendar.MONTH, val);
return (calendarToTimestamp(tmpCal));
TimestampaddMonths(Timestamp refDate, int nrOfMonthsToAdd)
Adds the number of months to the date.
Calendar calendar = Calendar.getInstance();
calendar.setTime(refDate);
calendar.add(Calendar.MONTH, nrOfMonthsToAdd);
Timestamp resultDate = new Timestamp(calendar.getTimeInMillis());
resultDate.setNanos(refDate.getNanos());
return resultDate;
java.sql.TimestampaddTime(java.sql.Timestamp start, int year, int month, int day)
Adds the time.
return new java.sql.Timestamp(start.getTime() + year * 365 * 24 * 60 * 60 * 1000
        + month * 30 * 24 * 60 * 60 * 1000 + day * 24 * 60 * 60 * 1000);
TimestampadjustTimestamp(Timestamp stamp, int adjType, int adjQuantity, TimeZone timeZone, Locale locale)
Perform date/time arithmetic on a Timestamp.
Calendar tempCal = toCalendar(stamp, timeZone, locale);
tempCal.add(adjType, adjQuantity);
return new Timestamp(tempCal.getTimeInMillis());
TimestampadjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity)
adjust Timestamp
Calendar tempCal = toCalendar(stamp);
tempCal.add(adjType, adjQuantity);
return new Timestamp(tempCal.getTimeInMillis());
TimestampadjustTimestamp(Timestamp timestamp, String timezone, int gmtOffset)
Adjust java.sql.Timestamp for the specified timezone change or gmt offset (using one overrides the other).
Timestamp ts = null;
if (timezone != null) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timestamp.getTime());
    Pattern p = Pattern.compile("([\\+\\-]?)([\\d]{1,2})[:]?([\\d]{1,2})?");
    Matcher m = p.matcher(timezone);
    if (m.find()) {
        String hh = m.group(2);
...
TimestampafterMinutes(Timestamp date, long min)
after Minutes
long fTime = date.getTime() + min * ONE_MINUTE;
return new Timestamp(fTime);
TimestampargMapTimestamp(Map argMap, Map argMapNotUsed, String key)
get the value from the argMap, throw exception if not there and required
String argString = argMapString(argMap, argMapNotUsed, key, false);
if (isBlank(argString)) {
    return null;
Date date = stringToDate2(argString);
return new Timestamp(date.getTime());
booleanbeforeTimestamp2Safety(Timestamp ts1, Timestamp ts2)
Safety compare two timestamp, skip null value
return ts2 != null && ts1.before(ts2);
longbetween(Timestamp t1, Timestamp t2)
between
if ((t1 != null) && (t2 != null)) {
    return t1.getTime() - t2.getTime();
return 0;