date format - Why minute is not considering when comparing two times in android? -


i want compare time current time.which should not less current time. here code:

try {                     date p_from=new simpledateformat("hh:mm").parse(from_time);                     date p_to=new simpledateformat("hh:mm").parse(to_time);                     date p_selected=new simpledateformat("hh:mm").parse(string.valueof(p_hour[0])+":"+string.valueof(p_min[0]));                       if (p_selected.before(p_to)&&p_selected.after(p_from)) {                         string min_str="";                         if (p_min[0]<10) {                             min_str=string.valueof("0"+p_min[0]);                         } else {                             min_str=string.valueof(p_min[0]);                         }                         tv_estimate_time.settext("pickup on "+string.valueof(p_hour[0])+":"+min_str);                         popupwindow.dismiss();                     } else {                          toast.maketext(getapplicationcontext(), "error in time", toast.length_short).show();                     }                  } catch (parseexception e) {                  log.d("tttt", "c="+log.getstacktracestring(e));                 } 

here p_from- start time(say 10:00) , p_to-is end time(17.15),p_selected- selected time(say 16:55). in p_selected p_hour[0]=16 , p_min[0]=55.

in if part checking whether time before end time , after start time.in cases date.before(ddate) , date.after(ddate) not comparing not considering minutes considering hours.

say if user had selected 16:55 before , after respective time , in if part returning false , goes else part.

i have no idea made mistake..need in advance.

try this:

//time checker     private boolean timecheck(long timeinput){          long currenttime = system.currenttimemillis();          long difference = currenttime- timeinput;         int seconds = (int) (difference / 1000);         int minutes = seconds / 60;          if( timeinput >= currenttime ){             return true;         }else{             return false;         }     } 

and then, in main program call procedure this:

    //if kept time string     if(timecheck(long.valueof(mytime)))     {     //not less current time     }else{     //less current time     } 

i suppose kept time string. changing time long string can use:

    string.valueof(mylongtime); 

i hope helps.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -