Java Hour Format formatHTTPDate(Date pTime)

Here you can find the source of formatHTTPDate(Date 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(Date pTime) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//from   w w w .j av  a  2  s  .c o m
     * 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. formatHttpDate(Date d)
  2. formatHttpDate(Date date)
  3. formatHttpDate(Date date)
  4. formatHttpDate(Date date)
  5. formatHTTPDate(Date date)
  6. formatInfo(String info)
  7. formatInternal(final Date date)
  8. formatInterval(long intervalMsec)
  9. formatLastModified(long lastModifiedTime)