-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
  • 131
  • 1
  • 2
  • 8

2 Answers2

1

use this

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

instead of this

 DateFormat df = new SimpleDateFormat("yyyy MMM dd");
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
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,547
  • 3
  • 16
  • 30