List of utility methods to do Timestamp
Timestamp | floorAsDate(Timestamp time) floor As Date Calendar cal = Calendar.getInstance(); cal.setTime(time); 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()); |
Date | fromDate(Timestamp timestamp) from Date if (timestamp == null) { return null; return new Date(timestamp.getTime()); |
Optional | fromTimestamp(Timestamp timestamp) from Timestamp if (timestamp == null) return Optional.empty(); try { return Optional.of(ZonedDateTime.ofInstant(timestamp.toInstant(), UTC)); } catch (DateTimeException e) { return Optional.empty(); |
Timestamp | generateTimestamp() Generate timestamp. java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis()); return now; |
Calendar | getBeforeDate(final Timestamp baseTime, final int period, final int unit) get Before Date Calendar deleteTimeCalendar = Calendar.getInstance();
deleteTimeCalendar.setTime(baseTime);
deleteTimeCalendar.add(unit, -1 * period);
return deleteTimeCalendar;
|
Timestamp | getCalendarTimestamp(Calendar cal) get Calendar Timestamp return new Timestamp(cal.getTime().getTime()); |
Timestamp | getCurentTimestamp() Gets the curent timestamp. return new Timestamp(System.currentTimeMillis()); |
String | getCurFullTimestampStr() get Cur Full Timestamp Str return formatTimestamp(getCurFullTimestamp());
|
java.sql.Timestamp | getCurrTimestamp() get Curr Timestamp return new java.sql.Timestamp(System.currentTimeMillis()); |
Timestamp | getCurTime2Timestamp() get Cur Time Timestamp Timestamp t = new Timestamp(System.currentTimeMillis()); String d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(t); Timestamp.valueOf(d2); return t; |