Java Long Number to Date formatDateHeader(final long date)

Here you can find the source of formatDateHeader(final long date)

Description

format Date Header

License

Apache License

Declaration

public static String formatDateHeader(final long date) 

Method Source Code

//package com.java2s;
/**// w  w  w .  j  a  va  2s .c om
 * Copyright (C) 2011-2018 Red Hat, Inc. (https://github.com/Commonjava/indy)
 *
 * 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.Calendar;
import java.util.Date;

import java.util.TimeZone;

public class Main {
    private static final String DATE_HEADER_FMT = "EEE, dd MMM yyyy HH:mm:ss";
    private static final String GMT_SUFFIX = " GMT";

    public static String formatDateHeader(final long date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(date));
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));

        return new SimpleDateFormat(DATE_HEADER_FMT).format(cal.getTime()) + GMT_SUFFIX;
    }

    public static String formatDateHeader(final Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));

        return new SimpleDateFormat(DATE_HEADER_FMT).format(date) + GMT_SUFFIX;
    }
}

Related

  1. formatDate(long timestamp, String format)
  2. formatDate(String format, long timestamp)
  3. formatDate2DateStr(long date)
  4. formatDate2DateStr(long date)
  5. formatDateForLog(long dateTs)
  6. formatDateHeader(final long date)
  7. formatDateHeader(long millis)
  8. formatDateHeader(long value)
  9. formatDateISO(long millis)