0

I spent about hour to solve problem, but I couldn't...

My date string is "06 Jan 2016", and I want to parse it to object Date.

I tried next method

SimpleDateFormat frmt2 = new SimpleDateFormat("dd MMM yyyy");   
Date date = frmt2.parse("06 Jan 2016");

And I got:

java.text.ParseException: Unparseable date: "06 Jan 2016" (at offset 3)

I tried Joda lib

DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM yyyy");
DateTime dt = formatter.parseDateTime("06 Jan 2016");

But I got same error:

Invalid format: "06 Jan 2016" is malformed at "Jan 2016"

Can you help me please to obtain the success in this simple problem.

Thank you very much.

Rinnion
  • 89
  • 1
  • 9

1 Answers1

9
  SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy  hh:mm", Locale.ENGLISH);

    Date theDate = format.parse("JAN 13,2014  09:15");

    Calendar myCal = new GregorianCalendar();
    myCal.setTime(theDate);

    System.out.println("Day: " + myCal.get(Calendar.DAY_OF_MONTH));
    System.out.println("Month: " + myCal.get(Calendar.MONTH) + 1);
    System.out.println("Year: " + myCal.get(Calendar.YEAR));
Ahsan Kamal
  • 1,085
  • 2
  • 13
  • 34