-
judge and jury
comparing two dates
I have two buttons one to start my process and another to finish I would like to then work out the total time it took me to complete my process but don't know how to compare the two.
Heres an aproximation of my code:
code:
btnStart.onPress = function(){
started = new Date();
}
btnFinish.onPress = function (){
finished = new Date();
totalTime = new Date (finished - started);
}
if anyone could help me with displaying the time in a text box as 09:05 instead of 9:5 that would help me aswell -
code:
startText.text = started.getHours()+":"+ started.getMinutes();
-
for your second problem, with displaying the time as 9:05, rather than 9:5, in the past i have just used an if statement for the seconds , if its less than 10, make a string = "0"+secs, and then display that string rahter than the actualy secs variable
-hope that helps; =)
-Steve
-
Senior Member
I normaly use getTimer() for the purpose you describe. However, sticking with your plan...
Code:
btnStart.onPress = function(){
started = new Date();
}
btnFinish.onPress = function (){
finished = new Date();
totalTime = new Date (finished.getTime() - started.getTime());
}
// String Formatting is a ***** in actionscript, sadly.
var hours = started.getHours();
var mins = started.getMinutes();
if (hours.length == 1)
hours = '0' + hours;
if (mins.length == 1)
mins = '0' + mins;
startText.text = hours + ':' + mins;
The same code with getTimer()
Code:
btnStart.onPress = function(){
started = getTimer();
}
btnFinish.onPress = function (){
totalTime = getTimer() - started;
// Or if you still want the date stuff...
// totalTime = new Date(getTimer() - started);
}
// Who needs hours and minutes anyway? :)
startText.text = (totalTime/1000) + " secs";
-
judge and jury
thanks people
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|