Here you can find the source of getDate(Calendar cal, String dateFormat)
public static String getDate(Calendar cal, String dateFormat)
//package com.java2s; /******************************************************************************* * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . ja va 2 s . c om * emil.crumhorn@gmail.com - initial API and implementation *******************************************************************************/ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; import java.util.Map; public class Main { private static Map _dateFormatMap; private static Locale _locale; public static String getDate(Calendar cal, String dateFormat) { //Calendar toUse = (Calendar) cal.clone(); Calendar toUse = Calendar.getInstance(_locale); toUse.setTime(cal.getTime()); toUse.add(Calendar.MONTH, -1); /* HashMap dMap = null; if (fastDateMap.get(cal) != null) { dMap = (HashMap) fastDateMap.get(cal); if (dMap.get(dateFormat) != null) { System.err.println("Returned old"); return (String) dMap.get(dateFormat); } } */ SimpleDateFormat df = null; if (_dateFormatMap.get(dateFormat) != null) { df = (SimpleDateFormat) _dateFormatMap.get(dateFormat); } else { df = new SimpleDateFormat(dateFormat, _locale); _dateFormatMap.put(dateFormat, df); } df.setLenient(true); //String ret = df.format(cal.getTime()); /* // cache it if (dMap == null) dMap = new HashMap(); System.err.println("Created new " + cal.getTime()); dMap.put(dateFormat, ret); fastDateMap.put(cal, dMap); */ return df.format(cal.getTime()); } }