Java Locale Format formatSmartDate(Date date)

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

Description

Format a date as returned for producing a portable player readable date.

License

LGPL

Parameter

Parameter Description
date The date to be formated.

Return

String The formatted date, "yy-MM-dd"

Declaration

public static String formatSmartDate(Date date) 

Method Source Code

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

import java.text.*;
import java.util.Date;
import java.util.Locale;

public class Main {
    /**/*from w w w . j a v a2 s .  c o  m*/
     * Format a date as returned for producing a portable player readable date.
     * (9 characters).
     * 
     * @param date
     *            The date to be formated.
     * 
     * @return String The formatted date, "yy-MM-dd"
     * 
     */
    public static String formatSmartDate(Date date) {
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US);
        try {
            SimpleDateFormat simpleFormatter = (SimpleDateFormat) formatter;
            simpleFormatter.applyPattern("yy-MM-dd");
            String result = simpleFormatter.format(date);
            return result;
        } catch (Exception e) {
            // Simple formatter not supported.
        }
        return "";
    }
}

Related

  1. formatNumberSameWidth(final double v)
  2. formatNumberUk(double inNumber, int inDecimalPlaces)
  3. formatNumberWithThousandSeparator(long number)
  4. formatPCT(Object num)
  5. formatPersent(Object input)
  6. formatString(Object[] args)
  7. formatString(String pattern, Object... args)
  8. formatString2Date(String dateString)
  9. formattedFromDouble(double d, int scale, Locale locale)