1

i have date object i m getting date as date object and converted as a string object but now i have to validate if current date is equal to next date which i m getting is greater then or less then

Date someDate = new Date(); // Or whatever
Date dayAfter = new Date(someDate.getTime() + TimeUnit.DAYS.toMillis( 2 ));
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
String DayafterdDate=dateFormat.format(dayAfter);
editoradddetail1.putString("days", formattedDate);
//current date  
Date date=new Date();
SimpleDateFormat simpleDateFormat= new SimpleDateFormat();
Date today = new Date(date.getTime() + TimeUnit.DAYS.toMillis(0 ));
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
String todaydDate=dateFormat.format(today);
Kush Patel
  • 1,228
  • 1
  • 13
  • 34
android_jain
  • 788
  • 8
  • 19

1 Answers1

3

You can compare two dates with number of ways. But you can use any from below:

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(valid_until);
if (new Date().after(strDate)) {
   //Your details
}

or

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(valid_until);
if (System.currentTimeMillis() > strDate.getTime()) {
  //Your details
}
ViramP
  • 1,659
  • 11
  • 11