Java Hour Format formatRFC822(Date date, String timezone)

Here you can find the source of formatRFC822(Date date, String timezone)

Description

Format given date as an RFC822 formatted date/time String.

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String formatRFC822(Date date, String timezone) 

Method Source Code

//package com.java2s;
/**/*from  w  ww .  ja  v  a  2 s .  c  om*/
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Format given date as an RFC822 formatted date/time String.
     * 
     * Uses current time if the given date is null.
     * 
     * @param date
     * @return
     */
    public static String formatRFC822(Date date, String timezone) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");

        if (timezone != null) {
            dateFormat.setTimeZone(TimeZone.getTimeZone(timezone));
        }

        String dateString = null;

        if (date != null) {
            dateString = dateFormat.format(date);
        }

        return dateString;
    }
}

Related

  1. formatRecyclingDate(String strDate)
  2. formatRFC1123(Date date)
  3. formatRfc3339Date(Date date)
  4. formatRFC822(Date date)
  5. formatRFC822(Date date, Locale locale)
  6. formatRfc822Date(Date date)
  7. formatRuntime(long runtime)
  8. formatSDate(java.util.Date date)
  9. formatShortDate(java.util.Date date)