Class DateFormatter


  • public final class DateFormatter
    extends Object
    A formatter for HTTP header dates, such as "Expires" and "Date" headers, or "expires" field in "Set-Cookie". On the parsing side, it honors RFC6265 (so it supports RFC1123). Note that:
    • Day of week is ignored and not validated
    • Timezone is ignored, as RFC6265 assumes UTC
    If you're looking for a date format that validates day of week, or supports other timezones, consider using java.util.DateTimeFormatter.RFC_1123_DATE_TIME. On the formatting side, it uses a subset of RFC1123 (2 digit day-of-month and 4 digit year) as per RFC2616. This subset supports RFC6265.
    See Also:
    RFC6265 for the parsing side, RFC1123 and RFC2616 for the encoding side.
    • Method Detail

      • parseHttpDate

        public static Date parseHttpDate​(CharSequence txt)
        Parse some text into a Date, according to RFC6265
        Parameters:
        txt - text to parse
        Returns:
        a Date, or null if text couldn't be parsed
      • parseHttpDate

        public static Date parseHttpDate​(CharSequence txt,
                                         int start,
                                         int end)
        Parse some text into a Date, according to RFC6265
        Parameters:
        txt - text to parse
        start - the start index inside txt
        end - the end index inside txt
        Returns:
        a Date, or null if text couldn't be parsed
      • format

        public static String format​(Date date)
        Format a Date into RFC1123 format
        Parameters:
        date - the date to format
        Returns:
        a RFC1123 string
      • reset

        public void reset()