Here you can find the source of formatDate(Date date)
Parameter | Description |
---|---|
date | a parameter |
public final static String formatDate(Date date)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS = "yyyy-MM-dd HH:mm:ss"; public final static String formatDate(String date) { String str = ""; if (date == null || date.equals("")) { str = ""; } else if (date.length() >= 10) { str = date.substring(0, 10); } else {/*from ww w . ja v a2 s. com*/ str = date; } return str; } /** * format date to the style yyyy-MM-dd HH:mm:ss * * @param date * @return */ public final static String formatDate(Date date) { return dateTimeToStr(date, DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS); } public final static String dateTimeToStr(Date date, String format) { SimpleDateFormat dateTimeFormat = new SimpleDateFormat(format); return dateTimeFormat.format(date); } }