Here you can find the source of format(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static String format(Date date)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.Map; public class Main { private static String DEFAULT_PATTERN = "yyyy-MM-dd"; private static Map<String, SimpleDateFormat> formats; /**/*from www . ja v a 2s .c o m*/ * * @param date * * @param pattern * * @return */ public static String format(Date date, String pattern) { if (!formats.containsKey(pattern)) pattern = DEFAULT_PATTERN; DateFormat format = formats.get(pattern); return format.format(date); } /** * @param date * @return String */ public static String format(Date date) { Iterator<SimpleDateFormat> iter = formats.values().iterator(); while (iter.hasNext()) { return iter.next().format(date); } return null; } }