Here you can find the source of formatDate(Date date, String pPatern)
Parameter | Description |
---|---|
date | The date to be formated. |
pPatern | The patern of the date |
public static String formatDate(Date date, String pPatern)
//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 ""; } }