My first attempt:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); Date date = formatter.parse(string);
It throws a ParseException, so I found this hack:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); TimeZone timeZone = TimeZone.getTimeZone("Etc/GMT"); formatter.setTimeZone(timeZone); Date date = formatter.parse(string);
That didn't work either, and now I'm stuck. It analyzes without problems if I just change the time zone to "GMT".
edit: An example line for parsing would be "2011-11-29 10:40:24 Etc / GMT"
edit2: I would prefer not to delete the time zone information completely. I am encoding a server that receives a date from an external user, so maybe other dates will have different time zones. More precisely: this particular date that I receive is obtained from the receipt from the Apple server after purchasing the application in the iphone application, but I could also receive dates from other sources.
pgsandstrom
source share