HTTP Last-Modified header contains date in following format (example):
Wed, 09 Apr 2008 23:55:38 GMT
What is the easiest way to parse java.util.Date from this string?
HTTP Last-Modified header contains date in following format (example):
Wed, 09 Apr 2008 23:55:38 GMT
What is the easiest way to parse java.util.Date from this string?
This should be pretty close
String dateString = "Wed, 09 Apr 2008 23:55:38 GMT";
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
Date d = format.parse(dateString);
DateUtil.parseDate(dateString) from apache http-components
(legacy: DateUtil.parseDate(dateString) (from apache commons-httpclient))
It has the correct format defined as a Constant, which is guaranteed to be compliant with the protocol.
RFC 2616 defines three different date formats that a conforming client must understand.
The Apache HttpClient provides a DateUtil that complies with the standard:
Date date = DateUtils.parseDate( headerValue );