Java Long Number to Date formatHttpDate(long d)

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

Description

format Http Date

License

Open Source License

Declaration

public static String formatHttpDate(long d) 

Method Source Code

//package com.java2s;
/**//from w w  w. ja va  2 s . c o  m
 * 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. formatDateTime(long time)
  2. formatDateTime(long timestampEpoch)
  3. formatDateTimeStamp(final long timeInMillis, final String dateFormatString)
  4. formateDate(Long date, String format)
  5. formatEpoch(long date)
  6. formatHTTPDate(long pTime)
  7. formatHttpDate(long time)
  8. getDatebyLong(long dt)
  9. getDateByLongTime(long time)