Here you can find the source of date2Str(Calendar c, String format)
public static String date2Str(Calendar c, String format)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private static final String FORMAT = "yyyy-MM-dd HH:mm:ss"; public static String date2Str(Calendar c) {// yyyy-MM-dd HH:mm:ss return date2Str(c, null); }/*from w ww . j a v a 2 s . c o m*/ public static String date2Str(Calendar c, String format) { if (c == null) { return null; } return date2Str(c.getTime(), format); } public static String date2Str(Date d) {// yyyy-MM-dd HH:mm:ss return date2Str(d, null); } public static String date2Str(Date d, String format) {// yyyy-MM-dd HH:mm:ss if (d == null) { return null; } if (format == null || format.length() == 0) { format = FORMAT; } SimpleDateFormat sdf = new SimpleDateFormat(format); String s = sdf.format(d); return s; } }