Java Long Number to Date formatDate(Long date, String fmt)

Here you can find the source of formatDate(Long date, String fmt)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Long date, String fmt) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
    private static final Map<String, ThreadLocal<DateFormat>> tlDateFormatMap = new ConcurrentHashMap<String, ThreadLocal<DateFormat>>();

    public static String formatDate(Date d, String fmt) {
        return getDateFormat(fmt).format(d);
    }/*from  w ww  . ja va2s  . c o m*/

    public static String formatDate(Long date, String fmt) {
        return getDateFormat(fmt).format(date);
    }

    public static String format(Date date, String fmt) {
        return getDateFormat(fmt).format(date);
    }

    public static DateFormat getDateFormat(String fmt) {
        ThreadLocal<DateFormat> tl = tlDateFormatMap.get(fmt);
        if (tl == null) {
            tl = threadLocalDateFormat(fmt);
            tlDateFormatMap.put(fmt, tl);
        }
        return tl.get();
    }

    private static ThreadLocal<DateFormat> threadLocalDateFormat(final String pattern) {
        ThreadLocal<DateFormat> tl = new ThreadLocal<DateFormat>() {
            protected DateFormat initialValue() {
                return new SimpleDateFormat(pattern);
            }
        };
        return tl;
    }
}

Related

  1. formatDate(Long date)
  2. formatDate(long date)
  3. formatDate(long date)
  4. formatDate(long date)
  5. formatDate(long date)
  6. formatDate(long date, String format)
  7. formatDate(long date, String langStr)
  8. formatDate(long dateValue)
  9. formatDate(long epochMillis)