Android - Time Comparison "hh:mm:ss a" format -
"i try compare 2 time in "hh:mm:ss a" format. not work in think. googled couldn't find proper answer. sorry cause i'm new programming."
i try compare time this:
string strsql = "select * " + table_schedule + " lecturer_id=? , schedule_day=? , schedule_endtime > ?";
schedule_endtime > ?
however, comparison has ignored am/pm caused result become this: eg. 12:00:00 pm bigger 02:00:00 pm.
hope can give tips or provide solution. appreciate it.
instead of comparing formatted string, compare value in milliseconds. take @ convert string date:
simpledateformat formatter = new simpledateformat("dd-mmm-yyyy"); string dateinstring = "7-jun-2013"; try { date date = formatter.parse(dateinstring); system.out.println(date); system.out.println(formatter.format(date)); } catch (parseexception e) { e.printstacktrace(); }
then once have 2 dates can compare them so:
boolean before = somedate.before(anotherdate);
or
boolean after = somedate.after(anotherdate);
or
somedate.gettime() < anotherdate.gettime();
side note: when store dates, store millisecond value , time zone. way don't need worry things this.
Comments
Post a Comment