org.opencms.util
Class CmsDateUtil

java.lang.Object
  extended by org.opencms.util.CmsDateUtil

public final class CmsDateUtil
extends java.lang.Object

Utilities to get and set formated dates in OpenCms.

Since:
6.0.0
Version:
$Revision: 1.23 $
Author:
Michael Emmerich

Field Summary
protected static java.util.TimeZone GMT_TIMEZONE
          The "GMT" time zone, used when formatting http headers.
protected static java.text.DateFormat HEADER_DEFAULT
          The default format to use when formatting http headers.
protected static java.text.DateFormat OLD_COOKIE
          The default format to use when formatting old cookies.
 
Method Summary
static java.lang.String getDate(java.util.Date date, int format, java.util.Locale locale)
          Returns a formated date String from a Date value, the formatting based on the provided options.
static java.lang.String getDateShort(long time)
          Returns a formated date String form a timestamp value, the formatting based on the OpenCms system default locale and the DateFormat.SHORT date format.
static java.lang.String getDateTime(java.util.Date date, int format, java.util.Locale locale)
          Returns a formated date and time String from a Date value, the formatting based on the provided options.
static java.lang.String getDateTimeShort(long time)
          Returns a formated date and time String form a timestamp value, the formatting based on the OpenCms system default locale and the DateFormat.SHORT date format.
static int getDaysPassedSince(java.util.Date dateLastModified)
          Returns the number of days passed since a specific date.
static java.lang.String getHeaderDate(long time)
          Returns a formated date and time String form a timestamp value based on the HTTP-Header date format.
static java.lang.String getOldCookieDate(long time)
          Returns a formated date and time String form a timestamp value based on the (old) Netscape cookie date format.
static long parseDate(int year, int month, int date)
          Returns the long value of a date created by the given integer values.
static long parseHeaderDate(java.lang.String timestamp)
          Parses a formated date and time string in HTTP-Header date format and returns the time value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GMT_TIMEZONE

protected static final java.util.TimeZone GMT_TIMEZONE
The "GMT" time zone, used when formatting http headers.


HEADER_DEFAULT

protected static final java.text.DateFormat HEADER_DEFAULT
The default format to use when formatting http headers.


OLD_COOKIE

protected static final java.text.DateFormat OLD_COOKIE
The default format to use when formatting old cookies.

Method Detail

getDate

public static java.lang.String getDate(java.util.Date date,
                                       int format,
                                       java.util.Locale locale)
Returns a formated date String from a Date value, the formatting based on the provided options.

Parameters:
date - the Date object to format as String
format - the format to use, see DateFormat for possible values
locale - the locale to use
Returns:
the formatted date

getDateShort

public static java.lang.String getDateShort(long time)
Returns a formated date String form a timestamp value, the formatting based on the OpenCms system default locale and the DateFormat.SHORT date format.

Parameters:
time - the time value to format as date
Returns:
the formatted date

getDateTime

public static java.lang.String getDateTime(java.util.Date date,
                                           int format,
                                           java.util.Locale locale)
Returns a formated date and time String from a Date value, the formatting based on the provided options.

Parameters:
date - the Date object to format as String
format - the format to use, see DateFormat for possible values
locale - the locale to use
Returns:
the formatted date

getDateTimeShort

public static java.lang.String getDateTimeShort(long time)
Returns a formated date and time String form a timestamp value, the formatting based on the OpenCms system default locale and the DateFormat.SHORT date format.

Parameters:
time - the time value to format as date
Returns:
the formatted date

getDaysPassedSince

public static int getDaysPassedSince(java.util.Date dateLastModified)
Returns the number of days passed since a specific date.

Parameters:
dateLastModified - the date to compute the passed days from
Returns:
the number of days passed since a specific date

getHeaderDate

public static java.lang.String getHeaderDate(long time)
Returns a formated date and time String form a timestamp value based on the HTTP-Header date format.

Parameters:
time - the time value to format as date
Returns:
the formatted date

getOldCookieDate

public static java.lang.String getOldCookieDate(long time)
Returns a formated date and time String form a timestamp value based on the (old) Netscape cookie date format.

Parameters:
time - the time value to format as date
Returns:
the formatted date

parseDate

public static long parseDate(int year,
                             int month,
                             int date)
Returns the long value of a date created by the given integer values.

Parameters:
year - the integer value of year
month - the integer value of month
date - the integer value of date
Returns:
the long value of a date created by the given integer values

parseHeaderDate

public static long parseHeaderDate(java.lang.String timestamp)
                            throws java.text.ParseException
Parses a formated date and time string in HTTP-Header date format and returns the time value.

Parameters:
timestamp - the timestamp in HTTP-Header date format
Returns:
time value as long
Throws:
java.text.ParseException - if parsing fails