Java HTTP Date getHttpDate(int days)

Here you can find the source of getHttpDate(int days)

Description

Format a date string in http-date format (Thu, 01 Dec 1994 16:00:00 GMT)

License

Open Source License

Parameter

Parameter Description
days offset in days from now

Return

String appropriate for Expires and other http fields

Declaration

public static String getHttpDate(int days) 

Method Source Code


//package com.java2s;
/*//  w ww . j av  a  2 s  . com
 * Copyright (C) 2012 joe
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /**
     * Format a date string in http-date format (Thu, 01 Dec 1994 16:00:00 GMT)
     * @param days offset in days from now
     * @return String appropriate for Expires and other http fields
     */
    public static String getHttpDate(int days) {

        Calendar calendar = Calendar.getInstance();
        long time = calendar.getTimeInMillis();
        time += days * 24 * 60 * 60 * 1000L;
        calendar.setTimeInMillis(time);
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        String ret = dateFormat.format(calendar.getTime());
        return ret;
    }
}

Related

  1. getHttpDate()
  2. gethttpDate()
  3. getHTTPDate()
  4. getHttpDate()
  5. getHttpDate(long l)
  6. getHttpDate(String date)
  7. getHttpDate(String value)
  8. getHttpDateFormat()