Here you can find the source of format(Calendar calendar)
Parameter | Description |
---|---|
calendar | the calendar to extract date to be formatted |
public static String format(Calendar calendar)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**// w w w . j a va 2s . c o m * Default date format to be used when formatting dates. */ private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); /** * Formats the specified date using the default date format. * * @param date the date to be formatted. * @return the specified date formatted according to default date format. */ public static String format(Date date) { return dateFormat.format(date); } /** * Formats specified date using the specified format. * * @param date the date to be formatted. * @param format the format to be used. * @return the specified date formatted according to specified format. * @see DateFormat */ public static String format(Date date, String format) { return new SimpleDateFormat(format).format(date); } /** * Extrats date from the specified calendar and formats it using default date format. * * @param calendar the calendar to extract date to be formatted * @return the date formatted according to default date format. */ public static String format(Calendar calendar) { return dateFormat.format(calendar.getTime()); } }