2381/how-can-we-compare-dates-in-java
You can refer the below code for comparing dates in java:
if(!historyDate.after(todayDate) && !futureDate.before(todayDate))
{ /* historyDate <= todayDate <= futureDate */ }
You can use compareTo():
date1.compareTo(date2);
Date today = new Date(); Date myDate = new Date(today.getYear(),today.getMonth()-1,today.getDay()); System.out.println("My Date is"+myDate); System.out.println("Today Date is"+today); if (today.compareTo(myDate)<0) System.out.println("Today Date is Lesser than my Date"); else if (today.compareTo(myDate)>0) System.out.println("Today Date is Greater than my date"); else System.out.println("Both Dates are equal");
public static String daysBetween(String day1, String day2) { String daysBetween = ""; SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date d1 = myFormat.parse(day1); Date d2 = myFormat.parse(day2); long diff = d2.getTime() - d1.getTime(); daysBetween = ""+(TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)); } catch (ParseException e) { e.printStackTrace(); } return daysBetween; }
To get the file extension, we can ...READ MORE
You can use ArrayUtils class remove method ...READ MORE
Your classpath is broken. Depending on how you ...READ MORE
From Java 1.5 you can use the String.format method. ...READ MORE
One possible solution could be using calendar ...READ MORE
You may refer this. This might work ...READ MORE
The following code might be helpful: public static ...READ MORE
I need a java.sql since I'm trying ...READ MORE
You can implement a Comparator which compares two Person objects, and ...READ MORE
To define Global Variable you can make ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.