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

StringformatString(Timestamp da)
format String
String datastring = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
datastring = sdf.format(da);
return datastring;
TimestampformatStringToTimeStamp(String s)
Format the TimeStamp like 2009-06-01 06:12:45
return Timestamp.valueOf(s.replace("T", " ").replace("Z", ""));
StringformattedDateTime(long timestamp)
formatted Date Time
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return dateFormat.format(new Date(timestamp));
StringformatTime(Date aTs_Datetime)
format Time
return format(aTs_Datetime, TIME_PATTERN_DEFAULT);
StringformatTime(Date date)
format Time
if (date == null) {
    return null;
} else {
    return monthDayYearformatter.format(date);
StringformatTime(Timestamp time, boolean onlyTime)
This method converts a JDBC format date into a String
if (time == null)
    return null;
return (onlyTime) ? userTimeOnlyFmt.format(time) : userTimeFmt.format(time);
StringformatTime(Timestamp ts, Locale locale)
Aus einem Timestampt die Zeit Locale abhaengig herausholen.
return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(ts);
StringformatTimeFromTimestamp(long ts, String fmt)
Format timestamp ts to string of format fmt, in UTC, for example, yyyy-MM-dd HH:mm:ss
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(fmt);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
    return sdf.format(new Date(ts));
} catch (Exception ex) {
return "";
StringformatTimestamp(Date date)
Formats a date object based on the format setting in compass.timestampFormat
if (date == null) {
    return "";
return getTimestampFormat().format(date);
StringformatTimestamp(Date timestamp)
Formats the Date into a timestamp string in YYYY-MM-dd HH:mm:ss GMT.
if (timestamp == null) {
    return "[No timestamp]";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(timestamp);