Andwyer
Andwyer

Reputation: 57

Parse HTTP 1.0 header date/time stamp in java

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:

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

Upvotes: 0

Views: 1306

Answers (2)

Vall0n
Vall0n

Reputation: 1688

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.

Upvotes: 2

user207421
user207421

Reputation: 310957

Use the DateUtil provided for the purpose.

Upvotes: 1

Related Questions