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

TimestampremoveTime(Timestamp ts)
remove Time
Calendar cal = Calendar.getInstance();
cal.setTime(ts);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return new Timestamp(cal.getTimeInMillis());
TimestampresetHourMinuteSecond(Timestamp timestamp, int hour, int minute, int second)
reset Hour Minute Second
Calendar calendar = Calendar.getInstance();
calendar.setTime(timestamp);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
return new Timestamp(calendar.getTimeInMillis());
TimestamproundToHour(Timestamp arg)
rounds the input value to the nearest whole hour
return new Timestamp(roundToSecs(arg, 60 * 60));
TimestamproundToSecond(Timestamp t)
round To Second
return new Timestamp((t.getTime() / 1000) * 1000);
TimestampsafeTimestamp(Date value)
safe Timestamp
return value != null ? new Timestamp(value.getTime()) : null;
voidsetTimestamp(byte[] ba, int offset, Timestamp val)
Put a Timestamp value "val" in a byte array "ba" starting at the offset "offset"
setLong(ba, offset, val == null ? 0 : val.getTime());
PreparedStatementsetTimestamp(int index, Timestamp t, PreparedStatement stmt)
set Timestamp
stmt.setTimestamp(index, t);
return stmt;
voidsetTimestampOrNull(PreparedStatement pstmt, int paramIndex, Timestamp value)
Sets a parameter in a PreparedStatement to either a value or null.
setParameterOrNull(pstmt, paramIndex, value, Types.TIMESTAMP);
java.sql.DatesqlDate(Timestamp t)
sql Date
return new java.sql.Date(t.getTime());
StringsqlDateConvertoStr(Timestamp date)
sql Date Converto Str
if (date == null)
    return null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);