Hoax
Hoax

Reputation: 1014

Groovy String To Date

I am trying to parse a String using the SimpleDateFormat, but the resulting Date seems to be off by a few months (day of the week, time (different time zone) and year are correct).

def headers = messageExchange.getResponseHeaders() 
def String dateHeader = headers.get("Date",null)

log.info "DATE:" + dateHeader

SimpleDateFormat dateFormat = new SimpleDateFormat("[EEE, dd MMM YYYY HH:mm:ss zzz]")
Date c = dateFormat.parse(dateHeader)

log.info c

OUTPUT:

DATE:[Thu, 08 Nov 2012 14:08:22 GMT]
INFO: Thu Jan 05 15:08:22 CET 2012

All ideas are welcome!

Upvotes: 0

Views: 1420

Answers (1)

doelleri
doelleri

Reputation: 19682

The date format should use 'y' instead of 'Y' for the year.

Upvotes: 1

Related Questions