Here you can find the source of formatDate(Date date)
Parameter | Description |
---|---|
date | the date that want to format to string |
public static String formatDate(Date date)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//w w w .j av a2 s .c om * default date format pattern */ public final static String DATE_FORMAT = "yyyy-MM-dd"; /** * format date with the default pattern * * @param date the date that want to format to string * @return the formated date */ public static String formatDate(Date date) { SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); return format.format(date); } /** * format date with the given pattern * * @param date the date that want to format to string * @param pattern the formated pattern * @return the formated date */ public static String formatDate(Date date, String pattern) { if (date == null) { return null; } SimpleDateFormat format = new SimpleDateFormat(pattern); return format.format(date); } }