Java Long Number to Time getOldCookieDate(long time)

Here you can find the source of getOldCookieDate(long time)

Description

Returns a formated date and time String form a timestamp value based on the (old) Netscape cookie date format.

License

Open Source License

Parameter

Parameter Description
time the time value to format as date

Return

the formatted date

Declaration

public static String getOldCookieDate(long time) 

Method Source Code


//package com.java2s;
/*//from  w  ww  . j a  v  a  2s . c o m
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /** The "GMT" time zone, used when formatting http headers. */
    protected static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
    /** The default format to use when formatting old cookies. */
    protected static final DateFormat OLD_COOKIE = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);

    /**
     * Returns a formated date and time String form a timestamp value based on the
     * (old) Netscape cookie date format.<p>
     * 
     * @param time the time value to format as date
     * @return the formatted date 
     */
    public static String getOldCookieDate(long time) {

        if (OLD_COOKIE.getTimeZone() != GMT_TIMEZONE) {
            // ensure GMT is used as time zone for the header generation
            OLD_COOKIE.setTimeZone(GMT_TIMEZONE);
        }

        return OLD_COOKIE.format(new Date(time));
    }
}

Related

  1. getElapsedTime(long start, long end)
  2. getElapsedTime(long startTime, long finishTime)
  3. getElapsedTimeSpecificationDescription(long sizeInBytes)
  4. getExpires(long maxAge)
  5. getHMSFromMills(long millSec)
  6. getReadableDate(long longTime)
  7. getServerTime(long offset)
  8. getShortTimeText(Long oldTime)
  9. getSimpleDate(long time)