android - how to use greater than or less than in date in java i have two date in simple date format or as a string -


this question has answer here:

i have date object m getting date date object , converted string object have validate if current date equal next date m getting greater or less

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

you can compare 2 dates number of ways. can use 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 } 

Comments

Popular posts from this blog

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -