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

java.sql.TimestampcreateDateTimestamp(java.util.Date date)
create Date Timestamp
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.setTime(date);
return new java.sql.Timestamp((calendar.getTime()).getTime());
Timestampdate2Timestamp(Date date)
date Timestamp
if (date == null) {
    return null;
return new Timestamp(date.getTime());
Timestampdate2Timestamp(Date value)
date Timestamp
if (value != null) {
    return new Timestamp(value.getTime());
return null;
TimestampdateAdd(Timestamp t1, Integer i, int type)
date Add
long interval = i * 1000 * 60 * 60 * 24l;
Timestamp t = null;
switch (type) {
case 1:
    interval = 1000 * 60 * 60 * i;
    t = new Timestamp(t1.getTime() + interval);
    break;
case 2:
...
TimestampdateAndTimeToTimestamp(Date data, Time hora)
date And Time To Timestamp
if (data != null) {
    Calendar calendarData = dateToCalendar(data);
    if (hora != null) {
        Calendar calendarHora = dateToCalendar(hora);
        calendarData.set(Calendar.HOUR_OF_DAY, calendarHora.get(Calendar.HOUR_OF_DAY));
        calendarData.set(Calendar.MINUTE, calendarHora.get(Calendar.MINUTE));
        calendarData.set(Calendar.SECOND, calendarHora.get(Calendar.SECOND));
        calendarData.set(Calendar.MILLISECOND, calendarHora.get(Calendar.MILLISECOND));
...
TimestampdateIntToTimestamp(int dateInt)
Converts an integer formatted to an instance of Timestamp
Calendar calendar = dateIntToCalendar(dateInt);
return new Timestamp(calendar.getTimeInMillis());
booleandatesDiffer(Timestamp a, Timestamp b)
dates Differ
if (a == null && b == null) {
    return false;
if (a != null && b == null) {
    return true;
if (a == null) {
    return true;
...
TimestampdateStringToTimestamp(String dateStr)
date String To Timestamp
Timestamp ts = new Timestamp(System.currentTimeMillis());
dateStr += " 00:00:00";
try {
    ts = Timestamp.valueOf(dateStr);
} catch (Exception e) {
    e.printStackTrace();
return ts;
...
java.sql.Timestampdatetime2ToTimestamp(long value, int fraction, int width)
datetime To Timestamp
final long millis = getMillisFromDatetime2(value);
final java.sql.Timestamp r = new java.sql.Timestamp(millis);
r.setNanos(nanosForFractionalValue(fraction, width));
return r;
StringdateTimeToString(Timestamp dt, String df)
DateTime convert to String.
String pstrDate = null; 
if (dt == null) {
    return "";
String formatStyle = null;
if ((df == null) || (df.equals(""))) {
    formatStyle = "yyyy-MM-dd HH:mm:ss";
} else {
...