Java Utililty Methods HTTP Date

List of utility methods to do HTTP Date

Description

The list of methods to do HTTP Date are organized into topic(s).

Method

StringgetHttpDate()
get Http Date
return getHttpDate(new Date());
StringgethttpDate()
Generate an rfc822 date for use in the Date HTTP header.
final String DateFormat = "EEE, dd MMM yyyy HH:mm:ss ";
SimpleDateFormat format = new SimpleDateFormat(DateFormat, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(new Date()) + "GMT";
StringgetHTTPDate()
get the date according to the HTTP standard
DateFormat httpDateFormat = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Locale.ENGLISH);
httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return httpDateFormat.format(new Date());
StringgetHttpDate()
convienence method returns current timestamp
return getHttpDate(new Date());
StringgetHttpDate(int days)
Format a date string in http-date format (Thu, 01 Dec 1994 16:00:00 GMT)
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;
...
StringgetHttpDate(long l)
get Http Date
return getDateString(l, "EEE, d MMM yyyy HH:mm:ss") + " GMT";
longgetHttpDate(String date)
Returns long representation of the HTTP defined RFC 1123 date format.
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
try {
    return dateFormat.parse(date).getTime();
} catch (Exception e) {
    return -1;
DategetHttpDate(String value)
get Http Date
if (value == null) {
    return null;
Date result = null;
try {
    result = getCxfHttpDateFormat().parse(value);
} catch (ParseException ex) {
    try {
...
SimpleDateFormatgetHttpDateFormat()
get Http Date Format
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
TimeZone tZone = TimeZone.getTimeZone("GMT");
dateFormat.setTimeZone(tZone);
return dateFormat;
SimpleDateFormatgetHttpDateFormat(String dataFormat, Locale defaultLocale, String defaultTimeZone)
Create a SimpleDateFormat instance given the specified template, locale, and time zone.
SimpleDateFormat dateFormat = new SimpleDateFormat(dataFormat, defaultLocale);
TimeZone tZone = TimeZone.getTimeZone(defaultTimeZone);
dateFormat.setTimeZone(tZone);
dateFormat.setLenient(false);
return dateFormat;