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

Timestamptrunc(Timestamp dayTime, String trunc)
Get truncated day/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.set(Calendar.HOUR_OF_DAY, 0);
...
TimestamptruncateFractionalSeconds(Timestamp timestamp)
truncate Fractional Seconds
Timestamp truncatedTimestamp = new Timestamp(timestamp.getTime());
truncatedTimestamp.setNanos(0);
return truncatedTimestamp;
TimestamptruncateTimestamp(Timestamp timestamp, String period)
Truncate the specified field of a java.sql.Timestamp
Timestamp ts = null;
if (period != null) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timestamp.getTime());
    if (period.equalsIgnoreCase(HOURLY)) {
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
...
TimestamptruncNanos(Timestamp timestamp)
trunc Nanos
Timestamp ts = new Timestamp(timestamp.getTime());
ts.setNanos((ts.getNanos() / 1000000) * 1000000);
return ts;
StringunformattedFromTimestamp(java.sql.Timestamp t)
Convert from a Timestamp to an unlocalized string with the format yyyymmddhhmmss.
return unformattedFromTimestamp(t, true, false);
TimestamputcToTimestamp(String utcTimestamp)
utc To Timestamp
Timestamp timestamp;
Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(utcTimestamp);
timestamp = new Timestamp(d.getTime());
return timestamp;
intweekNumber(Timestamp stamp, TimeZone timeZone, Locale locale)
week Number
Calendar tempCal = toCalendar(stamp, timeZone, locale);
return tempCal.get(Calendar.WEEK_OF_YEAR);
voidwriteTimestamp(ByteBuffer logBuf, Timestamp time)
Write a timestamp into the log.
writeLong(logBuf, time.getTime());
voidwriteTimestamp(Timestamp stamp, ObjectOutput out, long nullFlag)
write Timestamp
if (stamp != null) {
    long value = stamp.getTime();
    out.writeLong(value);
} else {
    out.writeLong(nullFlag);