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

booleanisValid(Timestamp validFrom, Timestamp validTo, Timestamp testDate)
Is it valid on test date
if (testDate == null)
    return true;
if (validFrom == null && validTo == null)
    return true;
if (validFrom != null && validFrom.after(testDate))
    return false;
if (validTo != null && validTo.before(testDate))
    return false;
...
Timestamplong2Timestamp(Long longValue)
long Timestamp
return new Timestamp(longValue);
longlongFromTimestamp(Timestamp ts)
Returns the number of milliseconds since the epoch represented by the time stamp ts, or #NULL_TIME if ts is null.
if (ts == null) {
    return NULL_TIME;
return ts.getTime();
Timestampmax(Timestamp ts1, Timestamp ts2)
Max date
if (ts1 == null)
    return ts2;
if (ts2 == null)
    return ts1;
if (ts2.after(ts1))
    return ts2;
return ts1;
TimestampmaxTime(Timestamp dayTime)
max Time
if (dayTime == null)
    dayTime = new Timestamp(System.currentTimeMillis());
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(dayTime.getTime());
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.add(GregorianCalendar.DAY_OF_YEAR, 1);
...
TimestampminusHours(Timestamp ts, int hours)
minus Hours
DateTime dateTime = new DateTime(ts.getTime(), DateTimeZone.UTC);
DateTime retval = dateTime.minusHours(hours);
Timestamp retts = new Timestamp(retval.getMillis());
retts.setNanos(ts.getNanos());
return retts;
TimestampminusOneSecond(Timestamp now)
minus One Second
return new Timestamp(now.getTime() - 1000);
DatenewDate(Timestamp time)
new Date
return new Date(time.getTime());
java.sql.TimestampnewTimestamp()
Create a new Timestamp.
return new java.sql.Timestamp(System.currentTimeMillis());
TimestampnewTimestamp(Date date)
new Timestamp
return newTimestamp(date.getTime());