Java Date Format dateFormat(DateFormat f, Date d)

Here you can find the source of dateFormat(DateFormat f, Date d)

Description

Formats a Date into a date/time string.

License

Open Source License

Parameter

Parameter Description
f The DateFormat to use.
d The Date to be formatted.

Return

Returns the formatted string.

Declaration

public static String dateFormat(DateFormat f, Date d) 

Method Source Code


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

import java.util.Date;
import java.text.DateFormat;

public class Main {
    /**//w ww .j  a  va 2  s.com
     * Formats a {@link Date} into a date/time string.  The reason this method
     * is necessary is because date formats are not thread-safe.  From the
     * {@link DateFormat} Javadoc:
     * <blockquote>
     * Date formats are not synchronized.  It is recommended to create separate
     * format instances for each thread. If multiple threads access a format
     * concurrently, it must be synchronized externally.
     * </blockquote>
     * @param f The {@link DateFormat} to use.
     * @param d The {@link Date} to be formatted.
     * @return Returns the formatted string.
     */
    public static String dateFormat(DateFormat f, Date d) {
        synchronized (f) {
            return f.format(d);
        }
    }
}

Related

  1. dateFormat(Date date, String format)
  2. dateFormat(Date date, String format)
  3. dateFormat(Date date, String pattern)
  4. dateFormat(Date date, String pattern)
  5. dateFormat(Date date, String pattern)
  6. dateFormat(int grain, TimeZone timeZone)
  7. dateFormat(java.util.Date date, String formatStr)
  8. dateFormat(long time)
  9. dateFormat(String date, String dateFormat)