Java yyyy formatShortDate(Date date)

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

Description

format Short Date

License

Open Source License

Declaration

public static String formatShortDate(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 formatShortDate(Date date) {
        return formatDate(date, "EEE, d MMM yyyy");
    }//from  ww w.ja  v  a2s. 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. formatG(Date date)
  2. formatHL7TSFormat4Date(Date time)
  3. formatJJJJMMTT(long time)
  4. formatPGNDate(final Date pDate)
  5. formatRTGSDate(java.util.Date date)
  6. formatSimpleDate(Date date)
  7. formatSimpleGermanDateString(Date date)
  8. formatSpaydDate(Date date, TimeZone tz)
  9. formatStr(Date date)