Java Hour Format formatDate(String format)

Here you can find the source of formatDate(String format)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(String format) 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    static String DEFAULT_FOMRAT = "MMddHHmmss";
    static Map<String, SimpleDateFormat> sdfMap = new TreeMap<String, SimpleDateFormat>();

    public static String formatDate(String format, Date date) {
        if (sdfMap.get(format) == null) {
            sdfMap.put(format, new SimpleDateFormat(format));
        }/* w  w  w .  j a  v  a 2  s. c  o m*/
        return sdfMap.get(format).format(date);
    }

    public static String formatDate(String format) {
        return formatDate(format, new Date());
    }

    public static String formatDate() {
        return formatDate(DEFAULT_FOMRAT, new Date());
    }
}

Related

  1. formatDate(java.util.Date dtFormat, String sFormatString)
  2. formatDate(Object obj, String format)
  3. formatDate(String date)
  4. formatDate(String date)
  5. formatDate(String dateTimeString)
  6. formatDate(String inputStr)
  7. formatDate(String pattern, Date date)
  8. formatDate2DateTimeStr()
  9. formatDate2DateTimeStr()