Here you can find the source of format(Calendar calendar, String formatString)
public static String format(Calendar calendar, String formatString)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static String format(Date date, String formatString) { if (date == null) return ""; SimpleDateFormat frmt = new SimpleDateFormat(formatString); return frmt.format(date); }// w w w . ja v a 2 s . co m public static String format(Date date, String formatString, TimeZone timezone) { if (date == null) return ""; SimpleDateFormat frmt = new SimpleDateFormat(formatString); if (timezone != null) frmt.setTimeZone(timezone); return frmt.format(date); } public static String format(Calendar calendar, String formatString) { if (calendar == null) return ""; SimpleDateFormat frmt = new SimpleDateFormat(formatString); Date date = calendar.getTime(); return frmt.format(date); } public static String format(Calendar calendar, String formatString, TimeZone timezone) { if (calendar == null) return ""; SimpleDateFormat frmt = new SimpleDateFormat(formatString); if (timezone != null) frmt.setTimeZone(timezone); else frmt.setTimeZone(calendar.getTimeZone()); Date date = calendar.getTime(); return frmt.format(date); } }