Recently in the writing of a HTML5 small game, the game will inevitably use the function of the timing. I am simply setting up a passedtime variable that does not have 60 frames + + once in the game Loop (fps=60). Then the time to convert the Passetime into 00:00 format is displayed. Although this method of computer time is not very accurate (because not every machine can be guaranteed to update 60 times in any second), but now the computer efficiency is very high, plus broswer progress, unless you use antique machine.
In fact, there are a lot of methods, here I simply use the following two functions:
function Gettimefromseconds (totalseconds) { if (TotalSeconds < 86400) { var dt = new Date ("01/01/2000 0:00"); C2/>dt.setseconds (totalseconds); return formattime (DT); } else { return null;} } function Formattime (dt) { var h = dt.gethours (), m = dt.getminutes (), s = dt.getseconds (), r = ""; if (H > 0) { R + = (H > 9? h.tostring (): "0" + h.tostring ()) + ":"; } R + = (M > 9? m.tostring (): "0" + m.tostring ()) + ":" r + = (S > 9?) S.tostring (): "0" + s.tostring ()); return r;}
You can use it like this:
$ ("#game_passed_time"). Text (Gettimefromseconds (gamepassedtime));
This will show the time, haha, I hope this simple thing didn't waste you a lot of time.
Front End Technology Group: 139761568
JavaScript converts seconds to hh-mm-ss time format