Java Locale Format format(final Date date, final String format)

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

Description

Format a date object into a date String using a given date format.

License

Open Source License

Parameter

Parameter Description
date the date object
format the date format

Return

the formatted date

Declaration

public static String format(final Date date, final String format) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    /**/* ww w  .  j  av  a2  s .c  o  m*/
     * Format a date object into a date String using a given date format.
     *
     * @param date
     *            the date object
     * @param format
     *            the date format
     * @return the formatted date
     */
    public static String format(final Date date, final String format) {
        DateFormat dateFormat = new SimpleDateFormat(format, Locale.getDefault());
        return dateFormat.format(date);
    }

    /**
     * Format a date object into a date String using the default date format.
     *
     * @param date
     *            the date object
     * @return the formatted date
     */
    public static String format(final Date date) {
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
        return dateFormat.format(date);
    }
}

Related

  1. format(Double number)
  2. format(double number)
  3. format(double number, int fractionDigits)
  4. format(double value)
  5. format(double values, boolean doNotFormat)
  6. format(final Date date, final String format)
  7. format(final double num, final int prec)
  8. format(final String bundleKey, final String messageKey, final Locale locale, final Object... arguments)
  9. format(int[] a)