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(long ts)
to Timestamp
if (ts == 0) {
    return null;
if (String.valueOf(ts).length() == 10) {
    ts = ts * 1000;
return new Timestamp(ts);
java.sql.TimestamptoTimestamp(long value)
to Timestamp
if (value <= 1) {
    return new java.sql.Timestamp(1000);
return new java.sql.Timestamp(value * 1000L);
java.sql.TimestamptoTimestamp(Object dateobj)
to Timestamp
return toTimestamp(dateobj.toString());
TimestamptoTimestamp(Object objInParam)
to Timestamp
Timestamp ts = null;
if (objInParam instanceof Timestamp)
    ts = (Timestamp) objInParam;
else if (objInParam instanceof Number)
    ts = new Timestamp(((Number) objInParam).longValue());
else if (objInParam instanceof Date)
    ts = new Timestamp(((Date) objInParam).getTime());
else if (objInParam instanceof String) {
...
TimestamptoTimestamp(String _sDate)
to Timestamp
Timestamp ts = null;
if (_sDate == null || "".equals(_sDate)) {
    return null;
ts = Timestamp.valueOf(_sDate + " 00:00:00.000000000");
return ts;
TimestamptoTimestamp(String dateTime)
to Timestamp
java.util.Date newDate = toDate(dateTime);
if (newDate == null)
    return null;
return new Timestamp(newDate.getTime());
java.sql.TimestamptoTimestamp(String dateTime)
Converts a date and time String into a Timestamp
java.util.Date newDate = toDate(dateTime);
if (newDate != null)
    return new java.sql.Timestamp(newDate.getTime());
else
    return null;
java.sql.TimestamptoTimestamp(String dt)
convert date String (yyyyMMdd or yyyyMMddHHmmss) to java.sql.Timestamp
if (dt == null) {
    throw new IllegalArgumentException("dt can not be null");
int len = dt.length();
if (!(len == 8 || len == 14)) {
    throw new IllegalArgumentException("dt length must be 8 or 14 (yyyyMMdd or yyyyMMddHHmmss)");
if (dt.length() == 8) {
...
TimestamptoTimestamp(String s)
Convert String to Timestamp
int len = s.length();
if (len >= 10) {
    int c4 = s.charAt(4);
    int c7 = s.charAt(7);
    if (c4 == '-' && c7 == '-') {
        if (len > 19) {
            if (s.charAt(10) == '-') {
                String s2 = s.substring(0, 10) + ' ' + s.substring(11, 13) + ':' + s.substring(14, 16) + ':'
...
TimestamptoTimeStamp(String sDate, String format)
to Time Stamp
Timestamp timeStampDate = null;
Date utilDate = null;
if (sDate != null) {
    utilDate = toUtilDate(sDate, format);
    timeStampDate = toTimeStamp(utilDate);
return timeStampDate;