Java Calendar Format format(Calendar calendar)

Here you can find the source of format(Calendar calendar)

Description

Extrats date from the specified calendar and formats it using default date format.

License

Open Source License

Parameter

Parameter Description
calendar the calendar to extract date to be formatted

Return

the date formatted according to default date format.

Declaration

public static String format(Calendar calendar) 

Method Source Code


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

Related

  1. format(Calendar calendar)
  2. format(Calendar calendar)
  3. format(Calendar calendar)
  4. format(Calendar calendar)
  5. format(Calendar calendar)
  6. format(Calendar calendar, String format)
  7. format(Calendar calendar, String format)
  8. format(Calendar calendar, String formatString)
  9. format(Calendar calendar, String pattern)