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 ww . j a v a 2 s.c o m*/ * emil.crumhorn@gmail.com - initial API and implementation *******************************************************************************/ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getDate(Calendar cal, String dateFormat) { Calendar toUse = (Calendar) cal.clone(); toUse.add(Calendar.MONTH, -1); SimpleDateFormat df = new SimpleDateFormat(dateFormat); df.setLenient(true); return df.format(cal.getTime()); } public static Date getDate(String str, String dateFormat) throws Exception { SimpleDateFormat df = new SimpleDateFormat(dateFormat); df.setLenient(false); return df.parse(str); } }