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

StringformatTimestamp(long timestamp)
format Timestamp
if (timestamp <= 0) {
    return "null";
} else {
    return timestampDateFormat.get().format(new Date(timestamp));
StringformatTimestamp(long timestamp)
format Timestamp
Date date = new Date(timestamp);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 
df.setTimeZone(tzUTC);
return timestamp + " (" + df.format(date) + ")";
StringformatTimestamp(long ts)
format Timestamp
return new SimpleDateFormat("HH:mm:ss.SSS", Locale.ROOT).format(new Date(ts));
StringformatTimestamp(String dateStr, String granularity)
format Timestamp
SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
SimpleDateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String timestamp = null;
try {
    if (dateStr == null) {
    } else if (dateStr.length() == 4) {
        Date yearDate = yearFormat.parse(dateStr);
...
StringformatTimestamp(Timestamp dataHora)
format Timestamp
if (dataHora == null)
    return "";
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return format.format(dataHora);
StringformatTimeStamp(Timestamp t)
Format the TimeStamp like 2009-06-01T06:12:45Z
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.MONTH_FIELD,
        DateFormat.LONG, Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
formatter.applyPattern("yyyy-MM-dd");
String timestamp = formatter.format(t);
formatter.applyPattern("hh:mm:ss");
return timestamp + "T" + formatter.format(t) + "Z";
StringformatTimestamp(Timestamp t, int type)
ACME timestamp formatter
DateFormat format = null;
switch (type) {
case FORMAT_DD_MM_YYYY_HH_MM_SS:
    format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    break;
case FORMAT_YYYY_MM_DD_HH_MM_SS:
    format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    break;
...
StringformatTimestamp(Timestamp timestamp)
format Timestamp
if (timestamp != null) {
    DateFormat formatter = new SimpleDateFormat(DATE_TIME_PATTERN);
    return formatter.format(timestamp.getTime());
return null;
StringformatTimestamp(Timestamp timestamp, int iType)
format Timestamp
String timeStr = "";
if (timestamp != null) {
    timeStr = getStrDate(new Long(timestamp.getTime()), iType);
return timeStr;
StringformatTimestamp(Timestamp timestamp, String pattern)
Formats a timestamp into a string.
return new SimpleDateFormat(pattern).format(timestamp);