Java Timestamp Format formatTimestamp(Long mills)

Here you can find the source of formatTimestamp(Long mills)

Description

format Timestamp

License

Apache License

Declaration

public static final String formatTimestamp(Long mills) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from w ww  .j a  v a  2s.c om*/
      * @param aDate
      * @return formated time by yyyy-MM-dd HH:mm:ss
      */
    public static final <T extends Date> String formatTimestamp(T date) {
        if (date == null)
            return null;
        SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return timestampFormat.format(date);
    }

    public static final String formatTimestamp(Long mills) {
        return formatTimestamp(new Date(mills));
    }

    /**
      * @param date
      * @param pattern: Date format pattern
      * @return
      */
    public static final <T extends Date> String format(T date, String pattern) {
        if (date == null)
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            String result = df.format(date);
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. formatTimestamp(Date timestamp)
  2. formatTimestamp(Date timestamp)
  3. formatTimestamp(final Date date)
  4. formatTimestamp(final Long timestamp)
  5. formatTimeStamp(long epochTime)
  6. formatTimestamp(long timestamp)
  7. formatTimestamp(long timestamp)
  8. formatTimestamp(long timestamp)
  9. formatTimestamp(long timestamp)