Java Utililty Methods Timestamp Format

List of utility methods to do Timestamp Format

Description

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

Method

StringformatDateHour(Date date)
format Date Hour
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
StringformatDateTime(Date date)
Format date time.
return (formatDate(date, "yyyy-MM-dd HH:mm:ss"));
StringformatDateTime(java.sql.Timestamp ts)
format Date Time
String temp = String.valueOf(ts);
if (temp != null && temp != "" && temp != "null")
    temp = temp.substring(0, 16);
else if (temp == "null")
    temp = "";
return temp;
StringformatDateTime(long ms)
Return the time in GMT
java.sql.Timestamp t = new java.sql.Timestamp(ms);
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, Locale.ENGLISH);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
String str = formatter.format(t);
return str;
StringformatDateTime(String dTime)
format Date Time
String dateTime = "";
if (dTime != null && !"".equals(dTime) && !dTime.startsWith("1900-01-01")) {
    Timestamp t = Timestamp.valueOf(dTime);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    dateTime = formatter.format(t);
return dateTime;
StringformatDateTime(Timestamp t, String pattern)
format Date Time
return formatDate(new Date(t.getTime()), STANDARD_DATETIME_PATTERN);
StringformatDateTimeStamp(final Date date)
format Date Time Stamp
return DATE_TIME_STAMP_FORMAT.format(date);
TimestampformatDateToTimestamp(String string)
yyyy-MM-dd
Timestamp result = null;
try {
    Date date = onlyDateFmt.parse(string);
    result = new Timestamp(date.getTime());
} catch (ParseException e) {
    e.printStackTrace();
return result;
...
intformatDateToUnixTimestamp(Date date)
format Date To Unix Timestamp
return Long.valueOf(date.getTime() / 1000).intValue();
TimestampformatDateWithCinderellaTime(Date date)
Format a date in the following format 2007-09-27 23:59:00
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(date);
gregorianCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23);
gregorianCalendar.set(GregorianCalendar.MINUTE, 59);
gregorianCalendar.set(GregorianCalendar.SECOND, 0);
Date formattedPassoutDate = gregorianCalendar.getTime();
return new Timestamp(formattedPassoutDate.getTime());