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

TimestampgetCurTimestamp()
get Cur Timestamp
return Timestamp.valueOf(formatTimestamp.format(new Date()));
java.sql.TimestampgetCurTimestamp()
get Cur Timestamp
java.util.Date today = new java.util.Date();
java.sql.Timestamp ts = new java.sql.Timestamp(today.getTime());
return ts;
StringgetTimeDifference(Timestamp startTime, Timestamp endTime)
Gets the time difference.
long timeInMilliseconds = endTime.getTime() - startTime.getTime();
int seconds = (int) (timeInMilliseconds / 1000);
int minutes = seconds / 60;
int milliseconds = (int) (timeInMilliseconds % 1000);
return minutes + " minute(s) " + seconds + " second(s) " + milliseconds + " millisecond(s)";
java.sql.TimegetTimeFromTimestamp(java.sql.Timestamp tsZeitpunkt)
get Time From Timestamp
if (tsZeitpunkt == null) {
    return null;
Calendar c = Calendar.getInstance();
c.setTimeInMillis(tsZeitpunkt.getTime());
long l = -MILLISEKUNDEN_EINER_STUNDE; 
l += c.get(Calendar.HOUR_OF_DAY) * MILLISEKUNDEN_EINER_STUNDE;
l += c.get(Calendar.MINUTE) * MILLISEKUNDEN_EINER_MINUTE;
...
longgetTimeNanoSec(Timestamp t)
get Time Nano Sec
long time = t.getTime();
int nanos = t.getNanos();
return (time * 1000000) + (nanos % 1000000);
TimestampgetTimeNextDay(Timestamp date)
get Time Next Day
long time = date.getTime();
time = time + 24 * 60 * 60 * 1000;
return new Timestamp(time);
TimestampgetTimeNextMonthFirstSec(Timestamp sysDate)
get Time Next Month First Sec
Calendar calendar = Calendar.getInstance();
calendar.setTime(sysDate);
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
...
StringgetTimePassedSince(Timestamp timestamp)
get Time Passed Since
String result = null;
Timestamp currentTime = getCurrentTimestamp();
long diff = currentTime.getTime() - timestamp.getTime();
boolean flag = false;
if (diff >= 0) {
    if (diff >= YEAR && !flag) {
        long d = diff / YEAR;
        flag = true;
...
StringgetTimeStr(Timestamp tsp)
get Time Str
if (tsp == null) {
    return "";
return dateToStr(new Date(tsp.getTime()));
StringgetTimeString(java.sql.Timestamp ts)
get Time String
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setTime(new java.util.Date(ts.getTime()));
return calendar.get(calendar.HOUR_OF_DAY) + ":" + calendar.get(calendar.MINUTE) + ":"
        + calendar.get(calendar.SECOND);