Package com.iizix

Class RFCDate


  • public class RFCDate
    extends java.lang.Object
    Date/Time Formats (Full Date). For more information, see RFC 2616 HTTP/1.1 June, 1999.

    HTTP applications have historically allowed three different formats for the representation of date/time stamps:

       Sun, 06 Nov 1994 08:49:37 GMT    ; RFC 822, updated by RFC 1123
       Sunday, 06-Nov-94 08:49:37 GMT   ; RFC 850, obsoleted by RFC 1036
       Sun Nov 6 08:49:37 1994          ; ANSI C's asctime() format
     
    The first format is preferred as an Internet standard and represents a fixed-length subset of that defined by RFC 1123 [8] (an update to RFC 822 [9]). The second format is in common use, but is based on the obsolete RFC 850 [12] date format and lacks a four-digit year. HTTP/1.1 clients and servers that parse the date value MUST accept all three formats (for compatibility with HTTP/1.0), though they MUST only generate the RFC 1123 format for representing HTTP-date values in header fields.

    All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception. For the purposes of HTTP, GMT is exactly equal to UTC (Coordinated Universal Time). This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, and MUST be assumed when reading the asctime format. HTTP-date is case sensitive and MUST NOT include additional LWS beyond that specifically included as SP in the grammar.

       HTTP-date = rfc1123-date | rfc850-date | asctime-date
       rfc1123-date = wkday "," SP date1 SP time SP "GMT"
       rfc850-date = weekday "," SP date2 SP time SP "GMT"
       asctime-date = wkday SP date3 SP time SP 4DIGIT
       date1 = 2DIGIT SP month SP 4DIGIT           ; day month year (e.g., 02 Jun 1982)
       date2 = 2DIGIT "-" month "-" 2DIGIT         ; day-month-year (e.g., 02-Jun-82)
       date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))  ; month day (e.g., Jun 2)
       time = 2DIGIT ":" 2DIGIT ":" 2DIGIT         ; 00:00:00 - 23:59:59
       wkday = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun"
       weekday = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday"
       month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
     
    Note: HTTP requirements for the date/time stamp format apply only to their usage within the protocol stream. Clients and servers are not required to use these formats for user presentation, request logging, etc.

    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      RFCDate() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static java.lang.StringgetCurrentUTC()
      Gets the current UTC date/time string according to RFC1123 date.
      static java.lang.StringgetCurrentUTC​(java.util.Date date)
      Gets the current UTC date/time string according to RFC1123 date.
      static java.util.DategetDate​(java.lang.String date)
      Gets a date from a string in either formats available in the HTTP/1.1 specification.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RFCDate

        public RFCDate()
    • Method Detail

      • getCurrentUTC

        public static java.lang.String getCurrentUTC​(java.util.Date date)
        Gets the current UTC date/time string according to RFC1123 date.
        Parameters:
        date - The date.
        Returns:
        The string.
      • getCurrentUTC

        public static java.lang.String getCurrentUTC()
        Gets the current UTC date/time string according to RFC1123 date.
        Returns:
        Current date string.
      • getDate

        public static java.util.Date getDate​(java.lang.String date)
        Gets a date from a string in either formats available in the HTTP/1.1 specification.
           Sun, 06 Nov 1994 08:49:37 GMT    ; RFC 822, updated by RFC 1123
           Sunday, 06-Nov-94 08:49:37 GMT   ; RFC 850, obsoleted by RFC 1036
           Sun Nov 6 08:49:37 1994          ; ANSI C's asctime() format
         
        Parameters:
        date - The date string.
        Returns:
        Date with the parsed date or null if error.