-7
String input="5/31/2013 2:30:56 PM";
SimpleDateFormatter s=new SimpleDateFormatter("MMMM dd, yyyy hh:mm a").Parse(input);
System.out.println(s);

I am expecting to this output "May 31,2013 2:30 PM" in this format but I am getting unparseable error if any one know the alternate way help me to resolve it.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Look at your input string and your format. They don't match. – Christopher Schneider Mar 07 '19 at 14:50
  • 3
    What's `SimpleDateFormatter`? In any case, your format string doesn't match your input, so it's not clear what you expect. – Dave Newton Mar 07 '19 at 14:51
  • 2
    There is not SimpleDateFormatter in the Java standard library - where does this class come from? Apart from that, having a method "Parse" that starts with a capital also indicates this is not part of the official Java API. – Peter Walser Mar 07 '19 at 14:52
  • I recommend you don’t use `SimpleDateFormat`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `LocalDateTime` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Mar 07 '19 at 14:56

2 Answers2

0

You use incorrect format of date. Passed string has format M/d/yyyy HH:mm:ss a

ZhenyaM
  • 676
  • 1
  • 5
  • 15
0

Change SimpleDateFormat("MMMM dd, yyyy hh:mm a") to SimpleDateFormat("M/d/yyyy H:mm:ss a")

Sapikelio
  • 2,594
  • 2
  • 16
  • 40