Java Hour Format format(Date date)

Here you can find the source of format(Date date)

Description

Formats the specified date using the default date format.

License

Open Source License

Parameter

Parameter Description
date the date to be formatted.

Return

the specified date formatted according to default date format.

Declaration

public static String format(Date date) 

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 {
    /**//from w ww.  j a  v a  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(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)
  9. format(Date date)