Java Hour Format formatHttpDate(Date date)

Here you can find the source of formatHttpDate(Date date)

Description

Format a Date according to the HTTP/1.1 RFC.

License

Open Source License

Parameter

Parameter Description
date the Date to format.

Return

a instance or null if the date was null.

Declaration

public static String formatHttpDate(Date date) 

Method Source Code

//package com.java2s;
/* ========================================================================== *
 *         Copyright (C) 2004-2006, Pier Fumagalli <http://could.it/>         *
 *                            All rights reserved.                            *
 * ========================================================================== *
 *                                                                            *
 * Licensed under the  Apache License, Version 2.0  (the "License").  You may *
 * not use this file except in compliance with the License.  You may obtain a *
 * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>.       *
 *                                                                            *
 * Unless  required  by applicable  law or  agreed  to  in writing,  software *
 * distributed under the License is distributed on an  "AS IS" BASIS, WITHOUT *
 * WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied.  See the *
 * License for the  specific language  governing permissions  and limitations *
 * under the License.                                                         *
 *                                                                            *
 * ========================================================================== */

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

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /** <p>The {@link SimpleDateFormat} RFC-822 date format.</p> */
    private static final String FORMAT_822 = "EEE, dd MMM yyyy HH:mm:ss 'GMT'";
    /** <p>The {@link TimeZone} to use for dates.</p> */
    private static final TimeZone TIMEZONE = TimeZone.getTimeZone("GMT");
    /** <p>The {@link Locale} to use for dates.</p> */
    private static final Locale LOCALE = Locale.US;

    /**//w  w  w .j  a  v  a  2s. c  o  m
     * <p>Format a {@link Date} according to the HTTP/1.1 RFC.</p>
     * 
     * @param date the {@link Date} to format.
     * @return a {@link String} instance or <b>null</b> if the date was null.
     */
    public static String formatHttpDate(Date date) {
        if (date == null)
            return null;
        SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_822, LOCALE);
        formatter.setTimeZone(TIMEZONE);
        return formatter.format(date);
    }
}

Related

  1. formatHours(long millis)
  2. formatHourTimeHToString(Date srcDate)
  3. formatHttpDate(Date d)
  4. formatHTTPDate(Date date)
  5. formatHttpDate(Date date)
  6. formatHttpDate(Date date)
  7. formatHTTPDate(Date pTime)
  8. formatInfo(String info)
  9. formatInternal(final Date date)