Java Locale Format formatDate(Date date, String pPatern)

Here you can find the source of formatDate(Date date, String pPatern)

Description

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

License

LGPL

Parameter

Parameter Description
date The date to be formated.
pPatern The patern of the date

Return

String The formatted date/

Declaration

public static String formatDate(Date date, String pPatern) 

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  ww .j  av  a2s.  c o m
     * Format a date as returned by the Apache HTTP Client date formatter into
     * an application specific format.
     * 
     * @param date
     *            The date to be formated.
     * 
     * @return String The formatted date, with pattern: EEE, d MMM yyyy kk:mm:ss
     *         z
     * 
     */
    public static String formatDate(Date date) {
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US);
        try {
            SimpleDateFormat simpleFormatter = (SimpleDateFormat) formatter;
            simpleFormatter.applyPattern("EEE, d MMM yyyy kk:mm:ss z");
            String result = simpleFormatter.format(date);
            return result;
        } catch (Exception e) {
            // Simple formatter not supported.
        }
        return null;

    }

    /**
     * Format a date as returned for producing a portable player readable date.
     * (9 characters).
     * 
     * @param date
     *            The date to be formated.
     * @param pPatern
     *            The patern of the date
     * @return String The formatted date/
     * 
     */
    public static String formatDate(Date date, String pPatern) {
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US);
        try {
            SimpleDateFormat simpleFormatter = (SimpleDateFormat) formatter;
            simpleFormatter.applyPattern(pPatern);
            String result = simpleFormatter.format(date);
            return result;
        } catch (Exception e) {
            // Simple formatter not supported.
        }
        return "";
    }
}

Related

  1. formatDate(Date date, String format)
  2. formatDate(Date date, String format, String localeText)
  3. formatDate(Date date, String pattern)
  4. formatDate(Date date, String pattern)
  5. formatDate(Date date, String pattern, Locale locale)
  6. formatDate(Date value, String pattern, TimeZone tz)
  7. formatDate(final Date dat, final String pattern)
  8. formatDate(final Date date, final String datepattern, TimeZone tz)
  9. formatDate(final Date date, final String format)