0

I'm using Apache Client to send HTTP/1.0 request and receive the response in java.

Now I met the problem: the header of response contains the property, "Date" which could be those three 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 // ANSI C's asctime() format

My problem is that I can use SimpleDateFormat to parse one type of those three formats but I can not find a good solution to parse ANY/ALL of those three formats.

(But HTTP/1.0 protocol requires to support all those formats, I can only support one of them)

Thanks indeed

Andwyer
  • 59
  • 6

2 Answers2

2

If you can't put the time in milliseconds into the date field of the header of the server response (which is not conform to the http specification), then i think the only way is the following:

create three formats then parse the date value with every format and return or work with the value that didn't throw a parse exception.

Hope it helps.

Vall0n
  • 1,601
  • 2
  • 14
  • 19
1

Use the DateUtil provided for the purpose.

user207421
  • 305,947
  • 44
  • 307
  • 483