This question already has an answer here:
I'm trying to parse this on Android:
Fri, 02 Oct 2015 10:01:00+0300
with this format EEE, dd MMM yyyy HH:mm:ssZ
, but doesn't work.
item_date = "Fri, 02 Oct 2015 18:07:00+0300";
SimpleDateFormat curFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssZ");
Date dateObj = null;
String newDateStr = item_date;
try {
dateObj = curFormater.parse(item_date);
} catch (ParseException e) {
e.printStackTrace();
}
In order to parse a String into a
Date
which contains certains words (e.g. for the month), then you need an appropriateLocale
corresponding to the language of these words. Since they are in english in your example you could use a language specific locale likejava.util.Locale.ENGLISH
or a country specific one, likejava.util.Locale.US
orLocale.UK
.Since you can pass the
Locale
to theSimpleDateFormat
constructor your instantiation could look like this:If you like to know the allowed date format words in your currently used
Locale
, then you can try the following snippet, which uses theDateFormatSymbols
class:This class provides corresponding methods to get months, the abbreviated months or the weekdays.
You can also pass a
Locale
to theDateFormatSymbols
constructor to get these strings from the specific locale.