java check two dates same day

Solutions on MaxInterview for java check two dates same day by the best coders in the world

showing results for - "java check two dates same day"
Oscar
23 Sep 2019
1public static boolean isSameDay(Date date1, Date date2) {
2    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
3    return fmt.format(date1).equals(fmt.format(date2));
4}
Roosevelt
26 Jan 2017
1public static boolean isSameDay(Date date1, Date date2) {
2    Calendar calendar1 = Calendar.getInstance();
3    calendar1.setTime(date1);
4    Calendar calendar2 = Calendar.getInstance();
5    calendar2.setTime(date2);
6    return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)
7      && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)
8      && calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH);
9}