Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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));
}
Comment

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);
}
Comment

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);
Comment

PREVIOUS NEXT
Code Example
Java :: java foreach arraylist 
Java :: convert bytebuffer to string 
Java :: java string to decimal 
Java :: java split string 
Java :: generate 5 digit random string in java 
Java :: java variables in annotations 
Java :: find minimum number in array java 
Java :: change number into array in java 
Java :: java return list 
Java :: java add button 
Java :: How to close jframe on click of button 
Java :: java restart program 
Java :: ! en java 
Java :: how to print hello world java 
Java :: Get the last Friday of a month in Java 
Java :: java random number between 2 values inclusive 
Java :: java download file from url 
Java :: Java make numbers 
Java :: java thread dump 
Java :: iterate map in java 8 using stream 
Java :: generate random password in spring boot 
Java :: method returns arraylist java 
Java :: java convert a string to char[] 
Java :: java print array backwards 
Java :: loop through an arraylist android studio 
Java :: how to modify string in java 
Java :: switch case java with char 
Java :: count occurrences of character in string java 8 
Java :: factors 
Java :: javac clear 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =