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

StringtimeStampForFileName(final String simpleDateFormat)
time Stamp For File Name
Date currentDateTime = new Date(System.currentTimeMillis());
SimpleDateFormat humanReadableFormat = new SimpleDateFormat(simpleDateFormat);
return humanReadableFormat.format(currentDateTime);
StringtimestampFormat(Date date)
timestamp Format
return getTimetampFormat().format(date);
StringtimestampFormat(final Date date)
timestamp Format
if (date == null) {
    return "";
return getTimestampFormat().format(date);
DatetimeStampFormat(Timestamp t)
time Stamp Format
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
dateFormat.format(t);
Date d = null;
try {
    d = dateFormat.parse(dateFormat.format(t));
} catch (ParseException e) {
    e.printStackTrace();
return d;
StringtimestampToFormattedDate(Long timestamp)
timestamp To Formatted Date
if (timestamp == null) {
    return null;
return DATE_FORMAT.format(new Date(timestamp));
StringtimestampToString(final Date ts, final String format, final String tzId)
timestamp To String
Date ret = ts;
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setTimeZone(TimeZone.getTimeZone(tzId));
if (ret == null) {
    ret = new Date();
return formatter.format(ret);
StringtimestampToString(Long timestamp, String formatStr)
timestamp To String
if (timestamp == null) {
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
try {
    return sdf.format(timestamp);
} catch (Exception e) {
    e.printStackTrace();
...
StringtimeToString(long timestamp, SimpleDateFormat format)
time To String
return format.format(new Date(timestamp));
StringtoDateFromTimestamp(String timestamp, String format)
to Date From Timestamp
DateFormat f = new SimpleDateFormat(format);
Date dateObj = new Date(Long.parseLong(timestamp));
return f.format(dateObj);
StringtoHumanTime(long timestamp, String format)
Returns a string representation of the timestamp using the specified format.
return (format == null) ? defaultSDF.format(timestamp) : new SimpleDateFormat(format).format(timestamp);