Java Long Number to Date formatDate(long millis)

Here you can find the source of formatDate(long millis)

Description

Formats the given date (as elapsed milliseconds) using the default format 'yyyy/MM/dd HH:mm:ss'.

License

Open Source License

Parameter

Parameter Description
millis the date

Return

a formatted date string

Declaration

public synchronized static String formatDate(long millis) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w  .  j a  v  a  2  s. co  m*/
 * #%L
 * Netarchivesuite - common
 * %%
 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
 *             the National Library of France and the Austrian National Library.
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** Default date format : yyyy/MM/dd HH:mm:ss */
    private static final SimpleDateFormat DEFAULT_DATE = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    /**
     * Formats the given date (as elapsed milliseconds) using the default format 'yyyy/MM/dd HH:mm:ss'.
     *
     * @param millis the date
     * @return a formatted date string
     */
    public synchronized static String formatDate(long millis) {
        return DEFAULT_DATE.format(new Date(millis));
    }

    /**
     * Formats the given date (as elapsed milliseconds) using the provided format pattern.
     *
     * @param millis the date
     * @param format the format pattern {@link SimpleDateFormat}
     * @return a formatted date string
     */
    public static String formatDate(long millis, String format) {
        return new SimpleDateFormat(format).format(new Date(millis));
    }
}

Related

  1. formatDate(long date, String format)
  2. formatDate(long date, String langStr)
  3. formatDate(long dateValue)
  4. formatDate(long epochMillis)
  5. formatDate(long millis)
  6. formatDate(long millis)
  7. formatDate(long millis, Locale locale)
  8. formatDate(long millis, String dateFormat)
  9. formatDate(long millisecond, String format)