Java Utililty Methods Timestamp to String

List of utility methods to do Timestamp to String

Description

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

Method

StringtimeStampToString(Timestamp stamp, String dateTimeFormat, TimeZone tz, Locale locale)
Localized Timestamp to String conversion.
DateFormat dateFormat = toDateTimeFormat(dateTimeFormat, tz, locale);
dateFormat.setTimeZone(tz);
return dateFormat.format(stamp);
StringtimestampToString(Timestamp timestamp)
timestamp To String
if (timestamp == null) {
    return null;
return timeFormatter().format(timestamp);
StringtimestampToString(Timestamp timestamp)
timestamp To String
SimpleDateFormat dateFormatForJqplotGraphs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormatForJqplotGraphs.format(new Date(timestamp.getTime()));
StringtimestampToString(Timestamp timestamp, String pattern)
timestamp To String
SimpleDateFormat simpledateformat = new SimpleDateFormat(pattern);
return simpledateformat.format(timestamp);
StringtimestampToString(Timestamp ts)
Conversion setting to 0 the nanoseconds, to deal with the mysql driver bug affecting the reverse translation (see stringToTimestamp()).
ts.setNanos(0);
return ts.toString();
StringtimestampToString(Timestamp ts, Calendar cal)
Formats a timestamp in JDBC timestamp escape format using the timezone of the passed Calendar.
cal.setTime(ts);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1; 
int day = cal.get(Calendar.DATE);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
String yearString = Integer.toString(year);
...
StringtimestampToStringFF(Timestamp date)
[timestampToStringFF function.].
[Detail description of method.]
if (date != null) {
    SimpleDateFormat dbDateTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    return dbDateTimeString.format(date);
return "";
StringtimestampToUTC(Timestamp marcTimestamp)
Convert a java.sql.Timestamp object (come from the database) to string in UTCdatetime format "yyyy-MM-dd'T'HH:mm:ssZ" format
if (null == marcTimestamp) {
    return "no timestamp";
} else {
    return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(marcTimestamp);
StringtoString(Timestamp t, String precision)
to String
if (t == null)
    return null;
SimpleDateFormat sdf;
if (precision.equals("minute"))
    sdf = new SimpleDateFormat(MINUTE_FORMAT);
else if (precision.equals("hour"))
    sdf = new SimpleDateFormat(HOUR_FORMAT);
else if (precision.equals("day"))
...
StringtoString(Timestamp value)
to String
String result = null;
if (value != null) {
    try {
        result = value.toString();
    } catch (Exception ex) {
return result;
...