Java Utililty Methods Timestamp Create

List of utility methods to do Timestamp Create

Description

The list of methods to do Timestamp Create are organized into topic(s).

Method

TimestamptoTimestamp(Date date)
to Timestamp
return toTimestamp(toLocalDateTime(date));
TimestamptoTimestamp(Date date)
Converts a Date to a Timestamp-object.
Calendar cal = new GregorianCalendar();
cal.setTime(date);
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.getTime().getTime());
TimestamptoTimeStamp(Date date, String time)
to Time Stamp
Calendar cal = Calendar.getInstance();
cal.setLenient(true);
boolean formatIs12 = time.endsWith("PM") || time.endsWith("AM");
String[] hhmmss = time.split(":");
if (hhmmss.length < 2)
    throw new IllegalArgumentException("invalid time");
if (hhmmss.length == 2) {
    String[] newTime = new String[3];
...
TimestamptoTimestamp(DateTime dt)
Null-safe method of converting a DateTime to a Timestamp.
if (dt == null) {
    return null;
} else {
    return new Timestamp(dt.getMillis());
TimestamptoTimestamp(final Calendar cal)
Converts a Calendar into a SQL timestamp.
final Timestamp ts = new Timestamp(cal.getTimeInMillis());
return ts;
TimestamptoTimestamp(final Instant instant)
TODO: Documentation
return new Timestamp(instant.toEpochMilli());
TimestamptoTimestamp(final int year, final int month, final int dayOfMonth, final int hour, final int minute, final int second, final int millsecond)
to Timestamp
Calendar cal = Calendar.getInstance();
cal.set(year, month - 1, dayOfMonth, hour, minute, second);
cal.set(Calendar.MILLISECOND, millsecond);
return new Timestamp(cal.getTimeInMillis());
TimestamptoTimestamp(final java.sql.Date date)
to Timestamp
Timestamp ts = new Timestamp(date.getTime());
return ts;
TimestamptoTimestamp(final String pValue)
Converts the string to a jdbc Timestamp, using the standard Timestamp escape format.
return Timestamp.valueOf(pValue);
TimestamptoTimestamp(java.sql.Date date)
to Timestamp
if (date == null) {
    return null;
return new Timestamp(date.getTime());