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 :: Error: Could not find or load main class Hello Caused by: java.lang.ClassNotFoundException: Hello studio visual code 
Java :: POST method) in spring rest api 
Java :: java inheritance example 
Java :: private method in interface java 
Java :: how to initialize a variable in java 
Java :: object in java 
Java :: generics Interface in java 
Java :: android studio tabbed activity 
Java :: properties object using a file 
Java :: prime factors of a number 
Java :: long in java 
Java :: convert python to java 
Java :: Java try...finally block 
Java :: stream reduce stringbuilder 
Java :: using for loop to search for an input java 
Java :: foreach() java 
Java :: what is a callable in java 
Java :: java gui bank account program 
Java :: Longest decreasing subsequence in java 
Java :: Remove ArrayList Elements using remove() function 
Java :: remove character stringbuffer 
Java :: how to select a audio from android programmaticly 
Java :: unique numbers in array java 
Java :: Iterating an Array Using While Loop 
Java :: EXPECTTIONS JAVA 
Java :: How to make sure a servlet is loaded at the application startup? 
Java :: mapToJsonString 
Java :: how to read json object from text file in java 
Java :: leak canary 
Java :: Java Method Overloading by changing the data type of parameters 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =