Java Utililty Methods Timestamp Field

List of utility methods to do Timestamp Field

Description

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

Method

intgetDiffSecond(long orgTimestamp, long desTimestamp)
get Diff Second
return (int) ((orgTimestamp - desTimestamp) / 1000);
longgetDiffTime(Timestamp last)
get Diff Time
Date date = new Date();
Timestamp now = new Timestamp(date.getTime());
long nowSec = now.getTime() / 1000;
long lastSec = last.getTime() / 1000;
if (nowSec > lastSec) {
    return nowSec - lastSec;
} else {
    return lastSec - nowSec;
...
intgetDiffYear(java.sql.Timestamp start, java.sql.Timestamp end)
Gets the diff year.
return end.getYear() - start.getYear();
intgetDiscrepancyNum(Timestamp time1, Timestamp time2)
get Discrepancy Num
int result = 0;
if (time1 != null && time2 != null) {
    long temp = time1.getTime() - time2.getTime();
    if (temp > 0) {
        result = (int) ((temp / (24 * 60 * 60 * 1000)));
    } else {
        result = -(int) (((temp / (24 * 60 * 60 * 1000))));
return result;
doublegetDouble(Timestamp ts)
Convert the timestamp to a double measured in seconds.
long seconds = millisToSeconds(ts.getTime());
return seconds + ((double) ts.getNanos()) / 1000000000;
LonggetDuration(final Timestamp start, final Date end)
Return the duration of a time interval (end-start) in milliseconds.
return ((start == null) || (end == null)) ? null : new Long(start.getTime() - end.getTime());
StringgetDurationHour(Timestamp time1, Timestamp time2, String direction)
get Duration Hour
String f = direction;
if (f == null) {
    f = "+";
long ctime1 = System.currentTimeMillis();
long ctime2 = System.currentTimeMillis();
if (time1 != null) {
    ctime1 = time1.getTime();
...
StringgetDurationMinute(Timestamp createTime, Timestamp finishTime)
get Duration Minute
String rtn = "0min";
if (createTime == null) {
    return rtn;
long ctime = createTime.getTime();
BigDecimal ct = new BigDecimal(Long.toString(ctime));
long ftime = System.currentTimeMillis();
if (finishTime != null) {
...
TimestampgetEndTimeOfMonth(Timestamp timestamp)
get End Time Of Month
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp.getTime());
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));
return new Timestamp(calendar.getTimeInMillis());
...
DategetEndTimeStampOfDate(Date date)
get End Time Stamp Of Date
if (date == null)
    return null;
String yyyymmdd = makeYYYYMMDD(date);
StringTokenizer tokenizer = new StringTokenizer(yyyymmdd, "/");
int year = Integer.parseInt(tokenizer.nextToken());
int month = Integer.parseInt(tokenizer.nextToken());
int day = Integer.parseInt(tokenizer.nextToken());
return new Timestamp(makeDateTime(year, month, day, 23, 59, 59).getTime());
...