Like you have described in your comment, You try to parse
a date like this:
String dt_time = "4/9/2016"+" "+"3:17 PM";
with a SimpleDateFormat
like this:
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
So you get an exception. To parse a date
like your date String
, you need this SimpleDateFormat
"d/M/yyyy h:mm a"
or you have to change your date string to:
"04/09/2016"+" "+"03:17 PM";
You are using a one numbered format for Your day, month and hour in your string, but try to parse
it with a double numbered format. I noticed that the API from SimpleDateFormat
has changed the description. The meaning is the same, but I think the old API description was better to understand. Look here: SimpleDateFormat
EDIT
Your code should be something like this:
String dt_time = "4/9/2016"+" "+"3:17 PM";
SimpleDateFormat format = new SimpleDateFormat("d/M/yyyy h:mm a");
Date date = format.parse(dt_time);
long millis = date.getTime();
MyCountDown mMyCountDown = new MyCountDown(millis,1000);
mMyCountDown.start();
EDIT 2
So now another assumption: The user selects some time in the future, let´s say 5:00 PM, and now it´s 4:00 PM. Then you have to get the current time like:
Calendar cal = Calendar.getInstance();
long currentMillis = cal.getTimeInMillis();
Then you have the millis from your timepicker in my example above. These are in the future. then you need to substract the current time from these millis:
long millisToCount = millis - currentMillis;
Then pass this to the timer:
MyCountDown mMyCountDown = new MyCountDown(millisToCount,1000);
mMyCountDown.start();
Then the timer should count down until the selected time is coming up. Is that what you want?