0

The date is "Mon Sep 24 15:27:21 GMT+03:00 2018". And tried to get this pattern like

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date startDate = simpleDateFormat.parse(startDateString);

And I get Unparseable Date Exception.What is the date pattern of this date in Android-JAVA?

Halil ÖZCAN
  • 109
  • 4
  • 1
    The pattern seems to be correct in Java.. [Here your code in an online compiler.](https://tio.run/##jZHfS8MwEMff91cceWoZlq4qSmUPgtW9FITuSdlDTI@Z2TQluc7Nsb@9ptu6ugliIOTHfe9z31wWfMkvFvlH04iCWwspl@VmAFDVb4UUYImTW5Za5qBcyMvIyHL@OgPutzIAMuv9BmAfa3MMPXDCw3kMLNUlZFhBdAWj6zi6iaMRPKXTYXgZhyFE4eiW3R0gC2coIFxRkElVFdiCHrVRnMCeX4yhxM8/MjyWJAmkaQp5DpNJrFTsnvgFazeY31U8xwYWaSoVvugSvR28JlkE3VUw/xFm7hXM90/M79Qtru@Ec/qrSsWNRe@sWUdStraEKtC1E7oAFWUv/Zeos@l17rYgOIl3r2/Xc@sgWQmsSLoPwpW/OQWjMUcwu3cKY7QBLURtDOYxsKHLOdAH7dw2zTc) Could you perhaps add the stacktrace and where you get the `startDateString` from? – Kevin Cruijssen Sep 25 '18 at 07:56
  • possible formats in android https://developer.android.com/reference/java/text/SimpleDateFormat – Aniruddh Parihar Sep 25 '18 at 08:01
  • I cannot reproduce on Java 10 on my Mac in Europe/Copenhagen time zone. I get `Mon Sep 24 14:27:21 CEST 2018`. You will want to post your full exception message, possibly even your stacktrace. – Ole V.V. Sep 25 '18 at 08:07
  • It is not reproducible error. Which version of Java are you using? – Khemraj Sharma Sep 25 '18 at 08:09
  • As an aside consider throwing away the long outmoded and notoriously troublesome `SimpleDateFormat` and friends, and adding [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your Android project in order to use `java.time`, the modern Java date and time API. It is so much nicer to work with. – Ole V.V. Sep 25 '18 at 08:11
  • Halil ÖZCAN, if the two questions I’ve linked to don’t help, please post a comment here and tag my name with an at sign in front of it, and I’ll either reopen your question or find more original questions of which yours could be a duplicate. I’m sure we can help you. – Ole V.V. Sep 25 '18 at 08:24
  • Try this code, Which is working fine, `String dateStr = "Mon Sep 24 15:27:21 GMT+03:00 2018"; DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy"); Date date; try { date = (Date)formatter.parse(dateStr); System.out.println(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); String formatedDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR); System.out.println("formatedDate : " + formatedDate); } catch (ParseException e) { e.printStackTrace(); }` – Archana Sep 25 '18 at 08:31
  • Thanks, @Archana, for wanting to contribute. Your code prints a stacktrace on a system with non-English locale (which I believe was the asker’s problem too, hence you don’t solve it). And why are you making the code more complex? Finally you are still using the outdated classes that we should avoid. – Ole V.V. Sep 25 '18 at 09:11

0 Answers0