I want to compare the date with current date and time to know whether date and time has been passed alredy or not. These are two date objects:
currentDateTime = 2019-11-22 05:25:19 AM
eventEndDateTime = 2019-11-22 05:45:00 AM
both are Date() objects.
and i am comparing like :currentDateTime.after(eventEndDateTime)
so it's giving me true.
But as we can see my current date before eventEndDateTime.
SimpleDateFormat endFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
TimeZone endTz = TimeZone.getTimeZone("UTC");
endFormatter.setTimeZone(endTz);
Date eventEndTime = null;
try {
eventEndTime = endFormatter.parse(endFormatter.format(new Date(eventDetailsResponce.getData().getEndMillis() * 1000)));
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat currentFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
TimeZone currentTz = TimeZone.getTimeZone(eventDetailsResponce.getData().getTimeZone());
currentFormatter.setTimeZone(currentTz);
Date currentTime = null;
try {
currentTime = currentFormatter.parse(currentFormatter.format(new Date()));
} catch (ParseException e) {
e.printStackTrace();
}
if (currentTime.after(eventEndTime)) {
//here i am getting true.
}
I have tried with Calendar calendar = Calendar.getInstance()
but i couldn't found any solution.