Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [OT] Subtracting two times in JavaScript



> Problem one is that Firebug keeps giving me the error "elapsed.slice is
> not a function".

Perhaps as elapsed is an integer, not a string; what you needed is even
simpler:

var elapsed = end.getTime() - currTime.getTime();
var seconds = Math.floor(elapsed/1000);

And if you didn't want the external sprintf dependency, what you had was
fine:

var minutes = Math.floor(seconds/60);
var hours = Math.floor(minutes/60);
minutes = minutes - (hours*60);

var remainTime = hours + ":" +
  (minutes<10 ? ("0"+minutes):minutes);


Darren



-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/gobet/  (Shodan Go Bet - who will win?)
http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links