Format Calendar by format passed in - Android java.util

Android examples for java.util:Calendar

Description

Format Calendar by format passed in

Demo Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{

    public static String getFormatedDate(Calendar c, String format) {
        try {/*from   w  ww.j a  v a2s .  co  m*/
            Date d = new Date(c.getTimeInMillis());
            SimpleDateFormat dateFormat = new SimpleDateFormat(format);
            return dateFormat.format(d);
        } catch (Exception e) {
            return new String();
        }
    }

}

Related Tutorials