Java Hour Format formatDateTime(Date date)

Here you can find the source of formatDateTime(Date date)

Description

format Date Time

License

Open Source License

Declaration

public static String formatDateTime(Date date) 

Method Source Code

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

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

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

public class Main {
    static Map<String, SimpleDateFormat> dateFormats = new HashMap<String, SimpleDateFormat>();
    static DecimalFormat df = new DecimalFormat("0.00");

    public static String formatDateTime(Date date) {
        return formatDate(date, "EEE, d MMM yyyy HH:mm:ss");
    }/*w ww .  j  av a  2 s. c o  m*/

    /**
     * Format a date with a given format. Formats are cached to prevent excessive use of 
     * DateFormat.
     * @param date
     * @param format
     * @return
     */
    public static String formatDate(Date date, String format) {

        if (!dateFormats.containsKey(format)) {
            dateFormats.put(format, new SimpleDateFormat(format));
        }

        if (date == null) {
            return "";
        }

        return dateFormats.get(format).format(date);
    }

    public static String format(Double d) {
        return df.format(d);
    }

    public static String format(Float f) {
        return df.format(f);
    }
}

Related

  1. formatDateTime(Calendar time)
  2. formatDateTime(Date d)
  3. formatDateTime(Date d)
  4. formatDateTime(Date d)
  5. formatDateTime(Date d)
  6. formatDateTime(Date date)
  7. formatDatetime(Date date)
  8. formatDateTime(Date date)
  9. formatDateTime(Date date)