Simple question I think, but I just can\'t seem to find an answer.
I am writing a cookie in a Java Servlet with the Cookie class which is sent to the browser in the resp
Java 8 now supplies an appropriate date formatter, DateTimeFormatter.RFC_1123_DATE_TIME:
OffsetDateTime oneHourFromNow
= OffsetDateTime.now(ZoneOffset.UTC)
.plus(Duration.ofHours(1));
String cookieExpires
= DateTimeFormatter.RFC_1123_DATE_TIME
.format(oneHourFromNow);
// E.g. "Tue, 8 Nov 2016 20:15:46 GMT"
This format is valid for the the expires
attribute, see RFC 6265 § 4.1.1, which defines the format to be an RFC 1123 date:
expires-av = "Expires=" sane-cookie-date sane-cookie-date =