Here you can find the source of formatDate(Calendar cal, String pattern)
public static String formatDate(Calendar cal, String pattern)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static final SimpleDateFormat date_sdf = new SimpleDateFormat("yyyy-MM-dd"); public static String formatDate() { return date_sdf.format(getCalendar().getTime()); }/*from w w w. j ava 2 s. c o m*/ public static String formatDate(Calendar cal) { return date_sdf.format(cal.getTime()); } public static String formatDate(Date date) { return date_sdf.format(date); } public static String formatDate(long millis) { return date_sdf.format(new Date(millis)); } public static String formatDate(String pattern) { return getSDFormat(pattern).format(getCalendar().getTime()); } public static String formatDate(Calendar cal, String pattern) { return getSDFormat(pattern).format(cal.getTime()); } public static String formatDate(Date date, String pattern) { return getSDFormat(pattern).format(date); } public static Calendar getCalendar() { return Calendar.getInstance(); } public static Calendar getCalendar(long millis) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(millis)); return cal; } private static SimpleDateFormat getSDFormat(String pattern) { return new SimpleDateFormat(pattern); } }