Java Hour Format formatHttpDate(Date d)

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

Description

format Http Date

License

Open Source License

Declaration

public static String formatHttpDate(Date d) 

Method Source Code

//package com.java2s;
/**/*from  w  w w  . j  a v a 2s .c  om*/
 * Copyright (c) 2013-2017, Kenneth Leung. All rights reserved.
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file epl-v10.html at the root of this distribution.
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 * You must not remove this notice, or any other, from this software.
 */

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

public class Main {
    private static ThreadLocal<SimpleDateFormat> _fmt = new ThreadLocal<SimpleDateFormat>() {

        public SimpleDateFormat initialValue() {
            SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
            f.setTimeZone(TimeZone.getTimeZone("GMT"));
            return f;
        }

    };

    /**
     */
    public static String formatHttpDate(long d) {
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.setTimeInMillis(d);
        return getSDF().format(gc.getTime());
    }

    public static String formatHttpDate(Date d) {
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.setTime(d);
        return getSDF().format(gc.getTime());
    }

    public static SimpleDateFormat getSDF() {
        return _fmt.get();
    }
}

Related

  1. formatHoraFormatadaHHMMSSStr(Date hora)
  2. formatHour(final Date date)
  3. formatHours(Locale locale, double totalhours)
  4. formatHours(long millis)
  5. formatHourTimeHToString(Date srcDate)
  6. formatHttpDate(Date date)
  7. formatHttpDate(Date date)
  8. formatHttpDate(Date date)
  9. formatHTTPDate(Date date)