I need to compare whether a date is after another date. For example, today is 12 January 2020. First, I tried this:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date pDate = dateFormat.parse("12/01/2020");
Date currentDate = new Date();
if (currentDate.after(pDate)) {
Toast.makeText(getApplicationContext(), "after", Toast.LENGTH_LONG).show();
}
Although both date are the same, I got the toast "after". Then I tried this:
Date currentDate = new Date();
if (currentDate.after(currentDate)) {
Toast.makeText(getApplicationContext(), "after", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "same day", Toast.LENGTH_LONG).show();
}
This time I got the toast "same day". Lastly I changed to date to 13/01/2020:
Date pDate = dateFormat.parse("13/01/2020");
Date currentDate = new Date();
if (currentDate.after(pDate)) {
Toast.makeText(getApplicationContext(), "after", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "before", Toast.LENGTH_LONG).show();
}
And I got the toast "before". The method seems working, but why the first code returned "after" even both date are the same?