List of utility methods to do Timestamp
Timestamp | removeTime(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()); |
Timestamp | resetHourMinuteSecond(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()); |
Timestamp | roundToHour(Timestamp arg) rounds the input value to the nearest whole hour return new Timestamp(roundToSecs(arg, 60 * 60)); |
Timestamp | roundToSecond(Timestamp t) round To Second return new Timestamp((t.getTime() / 1000) * 1000); |
Timestamp | safeTimestamp(Date value) safe Timestamp return value != null ? new Timestamp(value.getTime()) : null; |
void | setTimestamp(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()); |
PreparedStatement | setTimestamp(int index, Timestamp t, PreparedStatement stmt) set Timestamp stmt.setTimestamp(index, t);
return stmt;
|
void | setTimestampOrNull(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.Date | sqlDate(Timestamp t) sql Date return new java.sql.Date(t.getTime()); |
String | sqlDateConvertoStr(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); |