-1

I am able to use a DatePicker widget to save a Date to a String as follows:

dpResult = (DatePicker) findViewById(R.id.dpResult);
int day = dpResult.getDayOfMonth();
int month = dpResult.getMonth() -1;
int year = dpResult.getYear();


SimpleDateFormat dateFormatter = new SimpleDateFormat("MM-dd-yyyy");
Date d = new Date(year, month, day);
String strDate = dateFormatter.format(d);

This provides a String, e.g. for 09 Apr 2016: 04-09-3916

My question is how do I reverse this, to get the String value to show back in my DatePicker?

I have tried the following code:

String[] parts = strDate.split("-");
String part1 = parts[0];
String part2 = parts[1];
String part3 = parts[2];

month = Integer.parseInt(part1);
day = Integer.parseInt(part2);
year = Integer.parseInt(part3);

dpResult.init(year, month, day, null);

but the DatePicker shows a date of 31 Dec 2100, not 09 Apr 2016

AesculusMaximus
  • 195
  • 3
  • 14

1 Answers1

1

Use this

datepicker.init(year, month, day, null);
Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67