Java ZonedDateTime Format formatDate(ZonedDateTime dateTime)

Here you can find the source of formatDate(ZonedDateTime dateTime)

Description

Format a ZonedDateTime as RFC 1123 date format used in HTTP.

License

Apache License

Parameter

Parameter Description
dateTime The ZonedDateTime to format.

Return

the dateTime formatted as RFC 1123 compliant string

Declaration

public static String formatDate(ZonedDateTime dateTime) 

Method Source Code

//package com.java2s;
/**/*ww w  .  j a va 2 s.c o  m*/
 * Copyright (C) Posten Norge AS
 *
 * 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.time.ZoneId;
import java.time.ZonedDateTime;

import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;

public class Main {
    public static final ZoneId GMT = ZoneId.of("GMT");

    /**
     * Format a {@code ZonedDateTime} as RFC 1123 date format used in HTTP.
     * The format is {@link DateTimeFormatter#RFC_1123_DATE_TIME}.
     *
     * @param dateTime The {@code ZonedDateTime} to format.
     * @return the dateTime formatted as RFC 1123 compliant string
     */
    public static String formatDate(ZonedDateTime dateTime) {
        return RFC_1123_DATE_TIME.format(dateTime.withZoneSameInstant(GMT));
    }
}

Related

  1. format(ZonedDateTime zdt, DateTimeFormatter dtf)
  2. format(ZonedDateTime zonedDateTime)
  3. formatDate(ZonedDateTime dt)
  4. formatDate_ddMMYYYYHHmmss(ZonedDateTime now)
  5. formatDateAsShortDateLocalTime(ZonedDateTime moonDate, ZoneId tz)
  6. formatDateForGMT(ZonedDateTime moonDate)