Here you can find the source of formatHttpDate(Date date)
Format a Date according to the HTTP/1.1 RFC.
Parameter | Description |
---|---|
date | the Date to format. |
public static String formatHttpDate(Date date)
//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); } }