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(String str, String format)
to Timestamp
if (str == null) {
    return null;
try {
    return new Timestamp(parseDate(str, format).getTime());
} catch (Exception e) {
    return null;
TimestamptoTimestamp(String value)
to Timestamp
return Timestamp.valueOf(value);
TimestamptoTimestamp(String yyyymmddhhmmss)
to Timestamp
if (yyyymmddhhmmss == null) {
    return null;
String year = yyyymmddhhmmss.substring(0, 4);
if (Integer.valueOf(year) > 2400) {
    year = String.valueOf(Integer.parseInt(year) - 543);
String month = yyyymmddhhmmss.substring(4, 6);
...
java.sql.TimestamptoTimestamp2(long seconds, int fraction, int width)
to Timestamp
return timestamp2ToTimestamp(seconds, fraction, width);
TimestamptoTimestamp2(long seconds, int nanos)
to Timestamp
final java.sql.Timestamp r = new java.sql.Timestamp(seconds * 1000L);
r.setNanos(nanos);
return r;
StringtoTimestamp2(long value, int nanos, int meta)
to Timestamp
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp time = new java.sql.Timestamp(value * 1000L);
String strValue = sdf.format(time);
return strValue + microSecondToStr(nanos, meta);
TimestamptoTimestampByHour(Date date, int hour)
to Timestamp By Hour
String h = Integer.toString(hour);
if (h.length() == 1)
    h = "0" + h;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String now = sdf.format(date);
String endDate = now + " " + h + ":00:00";
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp timpestamp = null;
...
TimestamptoTimestampFromGMT(int yy, int mm, int dd, int hh, int mi, int ss)
to Timestamp From GMT
return toTimestampFromGMT(String.valueOf(yy), String.valueOf(mm), String.valueOf(dd), String.valueOf(hh),
        String.valueOf(mi), String.valueOf(ss));
TimestamptoTimestampFromLong(long millis)
Returns the Timestamp corresponding to millis, which denotes the point in time that many milliseconds since the epoch; returns null if millis is negative.
if (millis < 0) {
    return null;
return new Timestamp(millis);
TimestamptoTimestampFromTime(String time)
to Timestamp From Time
try {
    return toTimestampFromTime(Long.parseLong(time));
} catch (Exception iae) {
    return null;