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:
- how compare dates in java? 11 answers
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
Post a Comment