0
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.

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.