Hello i need to parse this string
Sun, 15 Aug 2010 3:50 PM CEST
I'm using SimpleDataFormat in this way
String date = "Sun, 15 Aug 2010 3:50 pm CEST";
DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy h:mm a Z");
Date d = formatter.parse(date);
but it throws an exception.
Can you help me please?
Thanks
I've solved in this way
} catch (Exception e) { Logger.error("Error while parsing data"); }
Remove Z from pattern and use Locale.US.
Thanks
My code is
and exception is
Thanks
This code:
Prints (without any exception):
So I guess something else is your problem... What is the exception you get?
SimpleDateFormat
is sensitive to theLocale
that is currently set. So it can be that there is a problem when trying to parse the format with your current one. With your constructor it usesLocale.getDefault()
to determine the setting.You could try to create the
DateFormat
explicitly using theLocale.US
vianew SimpleDateFormat(pattern, Locale.US)
and verify if the problem also exists in that case.