Reputation: 1484
I have string looks like: Sun, 27-Oct-2013 11:31:31 GMT
for make it a little simpler i do:
if (s.length() > 10)
s = s.substring(5, s.length() - 4);
after that
s = " 27-Oct-2013 11:31:31"
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date timestamp = null;
try {
timestamp = formatter.parse(s.trim());
} catch (ParseException e) {
e.printStackTrace();
}
It catch exception java.text.ParseException: Unparseable date: "27-Oct-2013 11:31:31"
Upvotes: 1
Views: 86
Reputation: 93842
You should specify a locale where months are spelled in english for your formatter, otherwise it will use your default locale.
SimpleDateFormat(String pattern)
Constructs a newSimpleDateFormat
using the specified non-localized pattern and theDateFormatSymbols
andCalendar
for the user's default locale.
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US);
Upvotes: 7