Mailing List Archive


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

Re: [tlug] [OT] Displaying time and starting from zero



Travis, Godwin,

Thank you for replying.

Here's the code. First, this is a function that adds time to my timer.
My timer works by marking a specific time in the future as a Unix time
stamp.

this.addTime = function(hours,minutes)
{
   // convert to milliseconds
   var addHours = hours*3600000;
   var addMinutes = minutes*60000;
   timeRemain.timeStamp = timeRemain.timeStamp + addHours + addMinutes;
}

And here's the function that displays the remaining time on the timer
(thanks to Darren for this). The time remaining is a result of the time
marked in the future minus the current time:

currTime = new Date();
var elapsed = timeRemain.timeStamp - currTime.getTime();
var seconds = Math.floor(elapsed/1000);
var minutes = Math.floor(seconds/60);
var hours = Math.floor(minutes/60);
minutes = minutes - (hours*60);
remainTime = hours + ":" + (minutes < 10 ? ("0"+minutes):minutes);
return remainTime;

The user has a button that will add one hour to the timer.

If I call the addTime function like this:

timeRemain.addTime(1,0);

... The display shows 0:59 remaining.

If I call the addTime function like this:

timeRemain.addTime(1,.1);

... the display shows 1:00 remaining. (.1 minutes was the lowest I could
go before it would change to 0:59)

-- 
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links