views:

1431

answers:

1

I am building a quiz and i need to calculate the total time taken to do the quiz. and i need to display the time taken in HH::MM::SS..any pointers?

+2  A: 

new Date().time returns the time in milliseconds.

var nStart:Number = new Date().time;

// Some time passes

var nMillisElapsed:Number = new Date().time - nStart;

var strTime:String = Math.floor(nMillisElapsed / (1000 * 60 * 60)) + "::" + 
   (Math.floor(nMillisElapsed / (1000 * 60)) % 60) + "::" + 
   (Math.floor(nMillisElapsed / (1000)) % 60);
Brian
do you take in account date in this example, what if somebody starts the quiz 1 minute before midnight ?
Omu