A message comes from the server in this format:

String strginDate = "Fri, 05 Jan 2018 15:19:14 GMT"; GMTToDDMMMYYYY(String strginDate) 

So, I parse it this way:

 private String GMTToDDMMMYYYY(String gmt){ DateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd mmm yyyy", Locale.getDefault()); Date d = null; try { d = sdf.parse(gmt); } catch (ParseException e) { e.printStackTrace(); } String dateStr = simpleDateFormat.format(d); return dateStr; } 

And I get the error:

java.text.ParseException: Unparseable date: "Fri, 05 Jan 2018 15:19:14 GMT" (at offset 0)

But I tried everything, like this:

 DateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'"); 

or

 DateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'"); 

and even so:

 DateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'"); 

But the result is the same.

Where am I doing wrong?

  • Found the answer, the problem was that you had to add a locale. I wrote Local.getDefault (), but it turned out that Locale.US - DevOma
  • Issue the solution found as an answer. - Eugene Krivenja

1 answer 1

Found the answer, the problem was that you had to add a Locale .

I wrote Local.getDefault() , but it turns out that Locale.US

 DateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.US);