Answers for "compare date with current date in java"

0

how to compare current date and time with another date and time in android

Date date1 = calendar1.getTime();
Date date2 = calendar2.getTime();
if (date1.compareTo(date2) > 0)
{    Log.i("app", "Date1 is after Date2");} 
else if (date1.compareTo(date2) < 0) 
{    Log.i("app", "Date1 is before Date2");} 
else if (date1.compareTo(date2) == 0) 
{    Log.i("app", "Date1 is equal to Date2");}
Posted by: Guest on April-28-2020
3

java compare dates

Date has before and after methods and can be compared to each other as follows:

if(todayDate.after(historyDate) && todayDate.before(futureDate)) {
    // In between
}
For an inclusive comparison:

if(!historyDate.after(todayDate) && !futureDate.before(todayDate)) {
    /* historyDate <= todayDate <= futureDate */ 
}
You could also give Joda-Time a go, but note that:

Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java.time (JSR-310).

Back-ports are available for Java 6 and 7 as well as Android.
Posted by: Guest on March-11-2021

Code answers related to "compare date with current date in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language