Q:

Calculating a Time Difference gives a wrong result

When I compare two dates together
Count the amount of the day incorrectly !!!
    final String myDate = "08/22/2018 20:56:03";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm/dd/yyyy HH:mm:ss");
    System.out.println("timeeeeeeeeeeeee" + "-" + simpleDateFormat);
    Date date = null;
    try {
        date = simpleDateFormat.parse(myDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    long endtime = date.getTime();
    Date d = null;
    try {
        d = simpleDateFormat.parse(simpleDateFormat.format(new Date(System.currentTimeMillis())));
    } catch (ParseException e2) {
        e2.printStackTrace();
    }
    Long ToCount = endtime -  d.getTime();

    CountDownTimer cdt = new CountDownTimer(ToCount, 1000) {
        public void onTick(long millisUntilFinished) {
            holder.timer.setText(""+ String.format(
                    " %d : %d : %d : %d ",
                    TimeUnit.MILLISECONDS.toDays(millisUntilFinished),
                    TimeUnit.MILLISECONDS.toHours(millisUntilFinished) -
                            TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millisUntilFinished)),
                    TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) -
                            TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
                    TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
                            TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))
            ));
        }
        public void onFinish() {
            // TODO Auto-generated method stub
            holder.timer.setText("done");
        }
    }.start();

I do not know exactly what the error is
The amount of wrong day is now calculated

A:

mm and MM are different.
MM is for Month.
mm is for minute.
So, the format must be MM/dd/yyyy HH:mm:ss.
And I don't know how you compared two values.
You can use equal() method. It compares its value. == compares its address.

