Class HttpDateTime

java.lang.Object
org.eclipse.jetty.http.HttpDateTime

public class HttpDateTime extends Object
HTTP Date/Time parsing and formatting.

Supports the following Date/Time formats found in both RFC 9110 (HTTP Semantics) and RFC 6265 (HTTP State Management Mechanism)

  • Sun, 06 Nov 1994 08:49:37 GMT - RFC 1123 (preferred)
  • Sunday, 06-Nov-94 08:49:37 GMT - RFC 850 (obsolete)
  • Sun Nov 6 08:49:37 1994 - ANSI C's asctime() format (obsolete)
  • Method Details

    • parseToEpoch

      public static long parseToEpoch(String datetime)
      Similar to parse(String) but returns unix epoch
      Parameters:
      datetime - the Date/Time to parse.
      Returns:
      unix epoch in milliseconds, or -1 if unable to parse the input date/time
    • parse

      public static ZonedDateTime parse(String datetime)

      Parses a Date/Time value

      Parsing is done according to the algorithm specified in RFC6265: Section 5.1.1: Date

      Parameters:
      datetime - a Date/Time string in a supported format
      Returns:
      an ZonedDateTime parsed from the given string
      Throws:
      IllegalArgumentException - if unable to parse date/time
    • format

      public static String format(TemporalAccessor datetime)
      Formats provided Date/Time to a String following preferred RFC 1123 syntax from both HTTP and Cookie specs.
      Parameters:
      datetime - the date/time to format
      Returns:
      the String representation of the date/time