I am new to Groovy (but already love it). I am not new to coding, but still have not had much experience.
What am I doing? I am extracting specific information from an excel file to create an XML message (SOAP) to send it to a web service. Everything has been working fine so far except date conversion .
I save string date in var
odate = 'Wed Oct 31 00:00:00 CET 2012'
I need to reformat this date to something like
"10/31/2012 10:09:00" (MM / dd / yyyy HH: mm: ss)
I tried to parse the date as mentioned in another question , but all I get is an exception.
String odate = 'Wed Oct 31 00:00:00 CET 2012' def parsedodate = new Date().parse('E MMM dd H:m:sz yyyy', odate) println parsedodate.format('MM/dd/yyyy h:m:s')
An exception was thrown on 10.31.2012 10:18:25 org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNUNG: Sanitizing stacktrace:
java.text.ParseException: Unsurpassed date: "Wed Oct 31 00:00:00 CET 2012"
Now, after a little reading and a few rounds of trial and error, I found out that somehow the parse method seems to only interpret German dates. The following works after manually changing the date of the string to the German format (which is somewhere around me).
String odate = 'Mi Okt 31 00:00:00 2012' //Mi = Wednesday, Okt = October, removed timezone def parsedodate = new Date().parse('E MMM dd H:m:s yyyy', odate) // removed the z println parsedodate .format('MM/dd/yyyy h:m:s')
However, I need a parser to accept the date format in English. What am I doing wrong)?