Sagar Maiyad
Sagar Maiyad

Reputation: 12733

java.text.parseexception unparseable date in android

String dt=mDateButton.getText().toString();
String tm =mTimeButton.getText().toString();
  try { 
    String format ="dd-MM-yyyy hh:mm a";

    DateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);

    String v_date_str = dt + " " + tm;
    //  String setDate =sdf.format(dt + " " + tm);
    Date v_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH).parse(v_date_str );

    DateFormat formatter = null;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");

    Log.d("sset: ", ""+formatter.format(v_date));
  } catch (ParseException e) {
    e.printStackTrace();
  }

Note: where dt = 2013-03-02 and tm = 21:54 . but i got an error on 9th line. i dont know what's the reason. please help me to get out of this problem. thank you in advance.

Upvotes: 0

Views: 2307

Answers (1)

Reimeus
Reimeus

Reputation: 159754

The problem is you have a DateFormat pattern mismatch.

Since v_date_str is 2013-03-02 21:54, you can match its format using:

new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH)

Upvotes: 4

Related Questions