Java Timestamp Format formatTimestamp(long timestamp)

Here you can find the source of formatTimestamp(long timestamp)

Description

format Timestamp

License

Open Source License

Declaration

public static String formatTimestamp(long timestamp) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static transient ThreadLocal<DateFormat> timestampDateFormat = new ThreadLocal<DateFormat>() {

        @Override//from  w ww  .j  av  a  2  s  .c o  m
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        }

        @Override
        public DateFormat get() {
            return super.get();
        }

        @Override
        public void set(DateFormat value) {
            super.set(value);
        }

        @Override
        public void remove() {
            super.remove();
        }

    };

    public static String formatTimestamp(long timestamp) {
        if (timestamp <= 0) {
            return "null";
        } else {
            return timestampDateFormat.get().format(new Date(timestamp));
        }
    }
}

Related

  1. formatTimestamp(Long mills)
  2. formatTimestamp(long timestamp)
  3. formatTimestamp(long timestamp)
  4. formatTimestamp(long timestamp)
  5. formatTimestamp(long timestamp)
  6. formatTimestamp(long timestamp)
  7. formatTimestamp(long ts)
  8. formatTimestamp(String dateStr, String granularity)
  9. formatTimestamp(Timestamp dataHora)