Java String to Date longToDateStringDefault(long time)

Here you can find the source of longToDateStringDefault(long time)

Description

long To Date String Default

License

Apache License

Declaration

public static String longToDateStringDefault(long time) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Map<String, SimpleDateFormat> formats = new HashMap();

    public static String longToDateStringDefault(long time) {
        return getFormatTimeString(new Date(time), "yyyyMMddHHmmss");
    }/*from   w ww .j  ava  2s  .  co  m*/

    public static String getFormatTimeString(Date date, String pattern) {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.format(date);
        }
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
        if (sDateFormat == null) {
            sDateFormat = new SimpleDateFormat(pattern);
            formats.put(pattern, sDateFormat);
        }
        return sDateFormat;
    }
}

Related

  1. getStringToDateTime(String dateStr, String formatStr)
  2. getTodateString()
  3. humanDateToDate(String date)
  4. LongToDateString(long l)
  5. longToDateString(long l)
  6. numberToDate(String dateString)
  7. putTimeStr14ToDate(String dateTimeStr)
  8. putTimeStr19ToDate(String dateTimeStr19)
  9. rfc3339ToDate(String s)