Here you can find the source of formatDate(final Date date)
Parameter | Description |
---|---|
date | The date to format. |
public static String formatDate(final Date date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); /**// w w w.j a v a 2s.co m * Date format pattern used to parse HTTP date headers in RFC 1123 format. */ public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz"; /** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(final Date date) { return formatDate(date, PATTERN_RFC1123); } /** * Formats the given date according to the specified pattern. The pattern * must conform to that used by the {@link SimpleDateFormat simple date * format} class. * * @param date The date to format. * @param pattern The pattern to use for formatting the date. * @return A formatted date string. * * @throws IllegalArgumentException If the given date pattern is invalid. * * @see SimpleDateFormat */ public static String formatDate(final Date date, final String pattern) { if (date == null) throw new IllegalArgumentException("date is null"); if (pattern == null) throw new IllegalArgumentException("pattern is null"); final SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US); formatter.setTimeZone(GMT); return formatter.format(date); } }