Java Date Format As formatDateHeader(final Date date)

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

Description

format Date Header

License

Apache License

Declaration

public static String formatDateHeader(final Date date) 

Method Source Code

//package com.java2s;
/**//from  ww  w . j  a v  a 2  s. c o m
 * 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. formatDateForLogFileName(Date date)
  2. formatDateForTAP(Date date)
  3. formatDateForXpath(Date date)
  4. formatDateGMT(Date date)
  5. formatDateHeader(final Date date)
  6. formatDateHMS(java.util.Date date)
  7. formatDateHMSMZ(Date date)
  8. formatDateList(List dateList)
  9. formatDateMedium(Date date)