Here you can find the source of formatDate(Calendar currentDate, String pattern)
public static String formatDate(Calendar currentDate, String pattern)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String formatDate(Calendar currentDate, String pattern) { if (currentDate == null || pattern == null) { throw new NullPointerException("The arguments are null !"); }/*w w w. ja va2 s. co m*/ Date date = currentDate.getTime(); return formatDate(date, pattern); } public static String formatDate(Date date, String pattern) { if (date == null || pattern == null) { throw new NullPointerException("The arguments are null !"); } SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(date); } public static String formatDate(String currentDate, String pattern) throws java.text.ParseException { if (currentDate == null || pattern == null) { throw new NullPointerException("The arguments are null !"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(currentDate); sdf.applyPattern(pattern); return sdf.format(date); } }