java - Why subtraction give the wrong result between numbers of clock? -
the program doesn't give error codes don't work correctly. when subtract between numbers of clock, makes wrong.
for example, when subtract between 15:00 , 18:00, results 12:00 instead of 3:00.
edit: found new bug. when compare time 15:00, result 12 every time. problem may in other things. (for instance, 15:00-16:00=12 or 15:00-19:00=12)
(in addition, use library github clock.)
private string starttime = ""; @bind(r.id.circle_seek_bar) circleseekbar mseekbar; list<item> messages = new arraylist<>(); private date finishing, starting; private long difference, a, b; simpledateformat format = new simpledateformat("hh:mm"); public void restart() { mseekbar.setissetstart(false); if (isaddmessage) { messages.add(new item(starttime, mseekbar.getcurrent())); starttime = mseekbar.getcurrent(); try { finishing = format.parse(starttime); b = finishing.gettime(); } catch (parseexception e) { e.printstacktrace(); } isaddmessage = false; } else { if (isfirst) { mseekbar.initinvaildstartangle(); isfirst = false; starttime = mseekbar.getcurrent(); try { starting =format.parse((mseekbar.getcurrent())); = starting.gettime(); } catch (parseexception e) { e.printstacktrace(); } } else { isaddmessage = true; difference = a-b; int minutes = (int) ((difference / (1000 * 60)) % 60); int hours = (int) ((difference / (1000 * 60 * 60)) % 24) - 1; text.settext((hours + ":" + minutes)); // text.settext(integer.tostring((int) difference)); }
it looks a
starting time , b
ending time.
b = finishing.gettime(); ... = starting.gettime();
yet when take difference subtract b
a
. backwards.
difference = a-b; //oops!
if want time elapsed, should subtract a
b
instead.
difference = b - a;
Comments
Post a Comment