Java Millisecond Format format(long millis, String pattern)

Here you can find the source of format(long millis, String pattern)

Description

Formats a date/time into a specific pattern.

License

Open Source License

Parameter

Parameter Description
millis the date to format expressed in milliseconds
pattern the pattern to use to format the date

Return

the formatted date

Declaration

public static String format(long millis, String pattern) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    /**// www.  j a  v a  2  s  . c  om
     * <p>
     * Formats a date/time into a specific pattern.
     * </p>
     * 
     * @param date
     *            the date to format
     * @param pattern
     *            the pattern to use to format the date
     * @return the formatted date
     */
    public static String format(Date date, String pattern) {
        return format(date, pattern, null);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern in a time zone and locale.
     * </p>
     * 
     * @param date
     *            the date to format
     * @param pattern
     *            the pattern to use to format the date
     * @param locale
     *            the locale to use, may be <code>null</code>
     * @return the formatted date
     */
    public static String format(Date date, String pattern, Locale locale) {
        if (locale == null)
            locale = Locale.getDefault();
        SimpleDateFormat df = new SimpleDateFormat(pattern, locale);
        return df.format(date);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern.
     * </p>
     * 
     * @param millis
     *            the date to format expressed in milliseconds
     * @param pattern
     *            the pattern to use to format the date
     * @return the formatted date
     */
    public static String format(long millis, String pattern) {
        return format(new Date(millis), pattern, null);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern in a time zone and locale.
     * </p>
     * 
     * @param millis
     *            the date to format expressed in milliseconds
     * @param pattern
     *            the pattern to use to format the date
     * @param locale
     *            the locale to use, may be <code>null</code>
     * @return the formatted date
     */
    public static String format(long millis, String pattern, Locale locale) {
        return format(new Date(millis), pattern, locale);
    }
}

Related

  1. format(final long timeInMillis)
  2. format(long millis)
  3. format(long millis)
  4. format(long millis)
  5. format(long millis)
  6. format(long milliseconds, String format)
  7. format(long timeMillis)
  8. format(long timeMillis, String pattern)
  9. format_duration(long millis)