Answers for "java check if dates are the same day"

1

java check two dates same day

public static boolean isSameDay(Date date1, Date date2) {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    return fmt.format(date1).equals(fmt.format(date2));
}
Posted by: Guest on August-14-2021
0

java check if dates are the same day

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
</dependency>

Then we can simply use the method isSameDay from DateUtils:

DateUtils.isSameDay(date1, date2);
Posted by: Guest on October-15-2021
0

java check two dates same day

public static boolean isSameDay(Date date1, Date date2) {
    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTime(date1);
    Calendar calendar2 = Calendar.getInstance();
    calendar2.setTime(date2);
    return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)
      && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)
      && calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH);
}
Posted by: Guest on August-14-2021

Code answers related to "java check if dates are the same day"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language