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

java.sql.TimestampgetTimestamp(Object value)
Convert an Object to a Timestamp, without an Exception
try {
    return toTimestamp(value);
} catch (ParseException pe) {
    pe.printStackTrace();
    return null;
java.sql.TimestampgetTimestamp(Object value, int columnType)
get Timestamp
if (value == null) {
    return null;
switch (columnType) {
case java.sql.Types.TIMESTAMP: {
    return (java.sql.Timestamp) value;
case java.sql.Types.TIME: {
...
TimestampgetTimestamp(ResultSet rs, String colName)
Returns the TimeStamp value for the specified column
if (colName == null || colName.length() == 0 || rs == null) {
    throw new IllegalArgumentException("getTimestamp: one or more parameters are null");
Timestamp timestamp = rs.getTimestamp(colName);
if (rs.wasNull()) {
    return null;
return timestamp;
...
TimestampgetTimestamp(ResultSet rs, String strColName)
Auxiliary method to avoid problems with null timestamp values
Timestamp value = rs.getTimestamp(strColName);
return rs.wasNull() ? null : value;
TimestampgetTimestamp(String date, String time)
get Timestamp
Calendar c = dateToCalendar(date);
c.set(Calendar.HOUR_OF_DAY, atoi(time.substring(0, 2)));
c.set(Calendar.MINUTE, atoi(time.substring(2, 4)));
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return new Timestamp(c.getTimeInMillis());
TimestampgetTimestamp(String dateStr)
get Timestamp
try {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm:ss");
    Timestamp date = new Timestamp(dateFormat.parse(dateStr).getTime());
    return date;
} catch (Exception ex) {
    System.out.println("Error: " + ex.toString());
    return null;
TimestampgetTimestamp(String dateString, String format)
get Timestamp
Date date = getDate(dateString, format);
if (date == null)
    return null;
return new Timestamp(date.getTime());
longgetTimestamp(String sqlDateTime)
get Timestamp
return Timestamp.valueOf(sqlDateTime).getTime();
TimestampgetTimestamp(String str)
get Timestamp
try {
    if (str == null || str.equals("")) {
        return null;
    if (str.length() == 10) {
        DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
        java.util.Date tempDate = df.parse(str);
        return new java.sql.Timestamp(tempDate.getTime());
...
TimestampgetTimestamp(String Str)
get Timestamp
Timestamp time = null;
try {
    time = java.sql.Timestamp.valueOf(Str);
} catch (Exception e) {
    System.out.println("getTimestamp error:" + e);
return time;