Here you can find the source of format(Calendar cal, String pattern)
public static String format(Calendar cal, String pattern)
//package com.java2s; /*// www . jav a 2 s . c o m * Copyright 2007 Sun Microsystems, Inc. * All rights reserved. You may not modify, use, * reproduce, or distribute this software except in * compliance with the terms of the License at: * http://developer.sun.com/berkeley_license.html */ import java.util.*; import java.text.SimpleDateFormat; public class Main { public static String format(Date date, String pattern) { // returns a String representation of the date argument, // formatted according to the pattern argument, which // has the same syntax as the argument of the SimpleDateFormat // class SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } public static String format(Calendar cal, String pattern) { SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(calendarToDate(cal)); } public static Date calendarToDate(Calendar cal) { return cal.getTime(); } }