-3

This is my code which I used to parse Date from String:

 DateFormat df = new SimpleDateFormat("yyyy MMM dd");
      Date date;
      try {
             date = df.parse(myButton.getText().toString()); //Button Text: Remind on: 15 SEP 2017 ( 10:10 ) PM
             String newDateString = df.format(date);
             String tempDate = newDateString;
             Log.d("","Test Date Parsed: "+ tempDate);
          } catch (ParseException e) {
            e.printStackTrace();
          }

But Log.d does not called when app is running. I want to save my button text to tempData like this: 15 09 2017 But try catch not called

SabbirTT
  • 111
  • 2
  • 7

2 Answers2

1

use this

SimpleDateFormat fmt = new SimpleDateFormat("dd-MM-yyyy");

instead of this

 DateFormat df = new SimpleDateFormat("yyyy MMM dd");
IntelliJ Amiya
  • 73,189
  • 14
  • 161
  • 193
AskNilesh
  • 63,753
  • 16
  • 113
  • 150
1

Please refer to this link. I think it is problem with a pattern. You use "yyyy MMM dd" which corresponds to 2015 09 15 date format. Please try "dd MM yyyy"

Mike
  • 2,117
  • 2
  • 15
  • 29