Java HTTP Date getHttpDateFormat(String dataFormat, Locale defaultLocale, String defaultTimeZone)

Here you can find the source of getHttpDateFormat(String dataFormat, Locale defaultLocale, String defaultTimeZone)

Description

Create a SimpleDateFormat instance given the specified template, locale, and time zone.

License

Apache License

Parameter

Parameter Description
dataFormat the template to be used
defaultLocale the local to be used
defaultTimeZone the time zone to be used

Return

A configured SimpleDataFormat instance.

Declaration

private static SimpleDateFormat getHttpDateFormat(String dataFormat, Locale defaultLocale,
        String defaultTimeZone) 

Method Source Code

//package com.java2s;
/**/*w w  w . ja  v a 2  s.co  m*/
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   This file is part of the LDP4j Project:
 *     http://www.ldp4j.org/
 *
 *   Center for Open Middleware
 *     http://www.centeropenmiddleware.com/
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   Copyright (C) 2014 Center for Open Middleware.
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   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.
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 *   Artifact    : org.ldp4j.framework:ldp4j-server-command:1.0.0-SNAPSHOT
 *   Bundle      : ldp4j-server-command-1.0.0-SNAPSHOT.jar
 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
 */

import java.text.SimpleDateFormat;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    private static final Locale DEFAULT_LOCALE = Locale.US;
    private static final String DEFAULT_TIME_ZONE = "GMT";
    private static final String RFC_822_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";

    /**
     * Create a {@code SimpleDateFormat} instance given the specified template,
     * locale, and time zone.
     * 
     * @param dataFormat
     *            the template to be used
     * @param defaultLocale
     *            the local to be used
     * @param defaultTimeZone
     *            the time zone to be used
     * @return A configured {@code SimpleDataFormat} instance.
     * @see {@link java.text.SimpleDateFormat}
     */
    private static SimpleDateFormat getHttpDateFormat(String dataFormat, Locale defaultLocale,
            String defaultTimeZone) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(dataFormat, defaultLocale);
        TimeZone tZone = TimeZone.getTimeZone(defaultTimeZone);
        dateFormat.setTimeZone(tZone);
        dateFormat.setLenient(false);
        return dateFormat;
    }

    /**
     * Get a date format template for managing the conversion of dates as
     * required by HTTP/1.1. The template uses {@value #DEFAULT_LOCALE_STR} as locale 
     * and {@value #DEFAULT_TIME_ZONE} as time-zone.
     * 
     * @see <a
     *      href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.4.3">RFC 2616 &mdash; Hypertext Transfer Protocol -- HTTP/1.1, 19.4.3 Conversion of Date Formats</a>
     * @see <a
     *      href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">RFC 2616 &mdash; Hypertext Transfer Protocol -- HTTP/1.1, 3.3.1 Full Date</a>
     */
    private static SimpleDateFormat getHttpDateFormat() {
        return getHttpDateFormat(RFC_822_DATE_FORMAT, DEFAULT_LOCALE, DEFAULT_TIME_ZONE);
    }
}

Related

  1. getHttpDate(int days)
  2. getHttpDate(long l)
  3. getHttpDate(String date)
  4. getHttpDate(String value)
  5. getHttpDateFormat()
  6. GetHTTPDateFormater()
  7. getHttpDateFormatter()
  8. getHttpDateString(Date date)