Java Long Number to Date formatHTTPDate(long pTime)

Here you can find the source of formatHTTPDate(long pTime)

Description

Formats the time to a HTTP date, using the RFC 1123 format, as described in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3" >RFC 2616 (HTTP/1.1), sec.

License

Open Source License

Parameter

Parameter Description
pTime the time

Return

a String representation of the time

Declaration

public static String formatHTTPDate(long pTime) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*from ww  w .j a va  2s  . c om*/
     * RFC 1123 date format, as recommended by RFC 2616 (HTTP/1.1), sec 3.3
     * NOTE: All date formats are private, to ensure synchronized access.
     */
    private static final SimpleDateFormat HTTP_RFC1123_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
            Locale.US);

    /**
     * Formats the time to a HTTP date, using the RFC 1123 format, as described
     * in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3"
     * >RFC 2616 (HTTP/1.1), sec. 3.3</a>.
     *
     * @param pTime the time
     * @return a {@code String} representation of the time
     */
    public static String formatHTTPDate(long pTime) {
        return formatHTTPDate(new Date(pTime));
    }

    /**
     * Formats the time to a HTTP date, using the RFC 1123 format, as described
     * in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3"
     * >RFC 2616 (HTTP/1.1), sec. 3.3</a>.
     *
     * @param pTime the time
     * @return a {@code String} representation of the time
     */
    public static String formatHTTPDate(Date pTime) {
        synchronized (HTTP_RFC1123_FORMAT) {
            return HTTP_RFC1123_FORMAT.format(pTime);
        }
    }
}

Related

  1. formatDateTime(long timestampEpoch)
  2. formatDateTimeStamp(final long timeInMillis, final String dateFormatString)
  3. formateDate(Long date, String format)
  4. formatEpoch(long date)
  5. formatHttpDate(long d)
  6. formatHttpDate(long time)
  7. getDatebyLong(long dt)
  8. getDateByLongTime(long time)
  9. getDateByMis(long m)