Here you can find the source of formatDate(Calendar calendar, String format)
public static String formatDate(Calendar calendar, String format)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String formatDate(String date, String format) { try {// w w w . j a v a 2 s. co m SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(new SimpleDateFormat("yyyy-MM-dd").parse(date)); } catch (ParseException e) { return ""; } } public static String formatDate(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } public static String formatDate(Calendar calendar, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(calendar.getTime()); } }