MCPcopy Create free account
hub / github.com/curtcox/JLHTTP / parseDate

Method parseDate

src/main/java/net/freeutils/httpserver/HTTPServer.java:2469–2479  ·  view source on GitHub ↗

Parses a date string in one of the supported #DATE_PATTERNS. Received date header values must be in one of the following formats: 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 ;

(String time)

Source from the content-addressed store, hash-verified

2467 * a valid date format in any of the supported formats
2468 */
2469 public static Date parseDate(String time) {
2470 for (String pattern : DATE_PATTERNS) {
2471 try {
2472 SimpleDateFormat df = new SimpleDateFormat(pattern, Locale.US);
2473 df.setLenient(false);
2474 df.setTimeZone(GMT);
2475 return df.parse(time);
2476 } catch (ParseException ignore) {}
2477 }
2478 throw new IllegalArgumentException("invalid date format: " + time);
2479 }
2480
2481 /**
2482 * Formats the given time value as a string in RFC 1123 format.

Callers 1

getDateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected