List of utility methods to do Timestamp
java.sql.Timestamp | addMonth(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)); |
Timestamp | addMonths(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.Timestamp | addTime(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); |
Timestamp | adjustTimestamp(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()); |
Timestamp | adjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity) adjust Timestamp Calendar tempCal = toCalendar(stamp); tempCal.add(adjType, adjQuantity); return new Timestamp(tempCal.getTimeInMillis()); |
Timestamp | adjustTimestamp(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); ... |
Timestamp | afterMinutes(Timestamp date, long min) after Minutes long fTime = date.getTime() + min * ONE_MINUTE; return new Timestamp(fTime); |
Timestamp | argMapTimestamp(Map 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()); |
boolean | beforeTimestamp2Safety(Timestamp ts1, Timestamp ts2) Safety compare two timestamp, skip null value return ts2 != null && ts1.before(ts2);
|
long | between(Timestamp t1, Timestamp t2) between if ((t1 != null) && (t2 != null)) { return t1.getTime() - t2.getTime(); return 0; |