Here you can find the source of formatDate(Date date, String pattern)
public static String formatDate(Date date, String pattern)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class Main { private static final Lock LOCK = new ReentrantLock(); public static String formatDate(Date date) { return formatDate(date, "yyyy-MM-dd"); }//from w ww. j av a 2 s .c o m public static String formatDate(Date date, String pattern) { LOCK.lock(); try { DateFormat fmt = new SimpleDateFormat(pattern); return fmt.format(date); } catch (Exception e) { e.printStackTrace(); return null; } finally { LOCK.unlock(); } } }