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

StringformatDefaultDate(Timestamp time)
Formats as a String the specified time, using the default date format: yyyy-MM-dd HH:mm:ss
if (time == null)
    time = getDefaultTimestamp();
return DEFAULT_DATE_FORMAT.format(time);
StringformatDuration(final long duration)
This is a convenient method for converting duration time/timestamp into a more human readable form.
final String format = "mm:ss";
final SimpleDateFormat df = new SimpleDateFormat(format);
df.setTimeZone(TimeZone.getTimeZone("UTC"));
return df.format(new Date(duration));
StringformatElapsed(long elapsed)
Format Elapsed Time
long miliSeconds = elapsed % 1000;
elapsed = elapsed / 1000;
long seconds = elapsed % 60;
elapsed = elapsed / 60;
long minutes = elapsed % 60;
elapsed = elapsed / 60;
long hours = elapsed % 24;
long days = elapsed / 24;
...
StringformatFileSize(Number data)
format File Size
if (data == null) {
    return null;
long size = data.longValue();
if (size > TB_SIZE) {
    DecimalFormat format = new DecimalFormat(PATTERN);
    return format.format((size * 1.0) / TB_SIZE) + " TB";
} else if (size > GB_SIZE) {
...
StringformatGMTTimestampToDate(Timestamp time)
format GMT Timestamp To Date
return toStringFormatGMTTime(time, DEFAULT_DATE_YMD_FORMAT);
StringformatJDBCTimeStamp(final java.util.Date date)
Obtain an JDBC timestamp string representation of the supplied date.
SimpleDateFormat sdf = new SimpleDateFormat(JDBC_TIMESTAMP_FORMAT);
sdf.setTimeZone(GMT);
return sdf.format(date);
StringformatJDBCTimeStamp(final java.util.Date date)
Obtain an JDBC timestamp string representation of the supplied date.
return new SimpleDateFormat(JDBC_TIMESTAMP_FORMAT).format(date);
StringformatMillis(long _millis)
format Millis
return new Timestamp(_millis).toString();
StringformatShortDateTime(Timestamp time)
Formats as a String the specified time.
if (time == null)
    time = getDefaultTimestamp();
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()).format(time);
voidformatStatement(PreparedStatement statement, List values)
format Statement
for (int i = 0; i < values.size(); ++i) {
    Object value = values.get(i);
    int index = i + 1;
    if (value instanceof String) {
        statement.setString(index, (String) value);
    } else if (value instanceof Date) {
        statement.setTimestamp(index, new Timestamp(((Date) value).getTime()));
    } else if (value instanceof Boolean) {
...