0

I've a date string like "Jan 11, 2017 2:08:00 AM". I want to convert this string to Date in "dd/MM/yyyy" format. My Code sample is below

 SimpleDateFormat  formatter = new SimpleDateFormat("dd/MM/yyyy");
            String dateStr= inSoya.get("selectedDate").toString(); //Jan 11, 2017 2:08:00 AM

            Date dd=formatter.parse(dateStr);// Error !

The excepiton is throwen at the last line where I am tring to parse.

Error Message is : Java.text.ParseException: Unparseable date: "Jan 5, 2017 2:08:00 AM"

So what should I do ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ilhan
  • 71
  • 1
  • 5
  • 1
    You need to tell the date formatter what format the date is that it will be given, not the format of the date you want – Rabbit Guy Aug 04 '17 at 18:01
  • Well , For example : incoming date is : "Feb 1, 2013 2:00:00 AM" and my pattern is : "MMM d, yyyy h:mm:ss a" but it doesn't work. Also I've tried MMM d, yyyy h:mm:ss aaa" but same result. – ilhan Aug 07 '17 at 07:20
  • read the two existing questions that are tagged. They should help you find your answer. – Rabbit Guy Aug 07 '17 at 13:42
  • Hi , find it thanks. – ilhan Aug 07 '17 at 14:18

0 Answers0