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

TimestampfloorAsDate(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());
DatefromDate(Timestamp timestamp)
from Date
if (timestamp == null) {
    return null;
return new Date(timestamp.getTime());
OptionalfromTimestamp(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();
TimestampgenerateTimestamp()
Generate timestamp.
java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis());
return now;
CalendargetBeforeDate(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;
TimestampgetCalendarTimestamp(Calendar cal)
get Calendar Timestamp
return new Timestamp(cal.getTime().getTime());
TimestampgetCurentTimestamp()
Gets the curent timestamp.
return new Timestamp(System.currentTimeMillis());
StringgetCurFullTimestampStr()
get Cur Full Timestamp Str
return formatTimestamp(getCurFullTimestamp());
java.sql.TimestampgetCurrTimestamp()
get Curr Timestamp
return new java.sql.Timestamp(System.currentTimeMillis());
TimestampgetCurTime2Timestamp()
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;