Java Calendar Format getDate(Calendar cal, String dateFormat)

Here you can find the source of getDate(Calendar cal, String dateFormat)

Description

get Date

License

Open Source License

Declaration

public static String getDate(Calendar cal, String dateFormat) 

Method Source Code

//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);
    }
}

Related

  1. formatDuration(Calendar t1, Calendar t2, boolean precise)
  2. formatRfc3339Calendar(Calendar cal)
  3. formatTime(Calendar cal, StringBuffer sb)
  4. formatToHTTPDate(Calendar calendar)
  5. getDate(Calendar cal, String dateFormat)
  6. print(Calendar[] calendar)
  7. printCalendar(Calendar cal)
  8. toInfo(Calendar calendar)
  9. toShort(Calendar calendar)