Here you can find the source of formatDateToString(java.util.Date date, int format)
Parameter | Description |
---|---|
date | the date |
format | the format type |
public final static String formatDateToString(java.util.Date date, int format)
//package com.java2s; import java.text.SimpleDateFormat; public class Main { private final static SimpleDateFormat[] DATE_FORMATTER = new SimpleDateFormat[] { new SimpleDateFormat("MMM d, yyy"), new SimpleDateFormat("EEE, MMM d, yyyy"), new SimpleDateFormat("MMM d, yyyy HH:mm:ss"), new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss"), new SimpleDateFormat("yyyy/MM/dd"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") }; /**/*from ww w .j a va2 s . c om*/ * Do format date with specified type. * * @param date * the date * @param format * the format type * @return the formatted date */ public final static String formatDateToString(java.util.Date date, int format) { String rel = null; if (date != null) { if (format >= DATE_FORMATTER.length || format < 0) { format = 0; } rel = DATE_FORMATTER[format].format(date); } return rel; } public final static String formatDateToString(java.util.Date date, String format) { String rel = null; if (date != null) { rel = new SimpleDateFormat(format).format(date); } return rel; } }