time comparison in two editText : android -
i have 2 edittext in enter time in , time out. googled couldn't find proper answer comparing 2 edittext having time in them. want create kind of validation function tells time in cannot less time out. eg if come office @ 09:00 cannot leave office @ 8:am
my time picker function 1 edittext :
{ final calendar c = calendar.getinstance(); mhour = c.get(calendar.hour_of_day); mminute = c.get(calendar.minute); // launch time picker dialog timepickerdialog tpd = new timepickerdialog(this, new timepickerdialog.ontimesetlistener() { @override public void ontimeset(timepicker view, int hourofday, int minute) { // display selected time in textbox txttime.settext(string.format("%02d:%02d", hourofday, minute)); } }, mhour, mminute, false); tpd.show(); }
public boolean timevalidator(string time1, string time2) { simpledateformat sdf = new simpledateformat("hh:mm"); boolean b = false; try { java.util.date arrtime = sdf.parse(time1); java.util.date deptime = sdf.parse(time2); // function check whether time after time b = deptime.after(arrtime); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } return b; }
provide values of edittexts in function parameters. there has been ".after" method used in snippet, 1 - ".before" can used well.
check :
if(timevalidator(et1.gettext().tostring(), et2.gettext().tostring()) { // } else { // }
Comments
Post a Comment