PDA

View Full Version : Display zero in front of timer numbers


munza101
01-08-2006, 10:11 PM
Hi I am making a time (clock) but i am having trouble displaying 0 in it

eg I get 1:2 am
when it should look like 1:02 am

I put the code "if" in front of the minutes and every second a 0 adds infront of it so it looks like this: 01 001 0001 and so on.

I also tried to add a zero number if the number is below 10 but the zero is in the wrong spot

Can anone help me make a zero in front of the number???

this is the code i have so far:

myMinute = 00;
myHour = 12;
myTimer = setInterval(wait, 1000);
function wait() {
mySeconds++;
if (mySeconds == 60) {
myMinute++;
mySeconds = 0;
}
if (mySeconds<10) {
myZero = 0;
} else {
myZero = "";
}
if (myMinute == 60) {
myHour++;
myMinute = 0;
}
if(myHour >= 12){
ampm = "pm";
}else{
ampm = "am";
}
if(myHour == 0){
myHour = 12;
}
if(myHour > 12){
myHour-=12;
}
if (myMinute < 10)
myMinute = "0" + myMinute;
}

chrisxkelley
01-10-2006, 05:32 AM
check out this tutorial, it looks like built in functions way simplify making a clock

http://www.smartwebby.com/Flash/digital_clock.asp

CyanBlue
01-10-2006, 07:47 PM
The same logic should work in F8...
// http://proto.layer51.com/d.aspx?f=1229
// Number: Zero Pads number to n places
// author: alex_tea
// Submitted: 04.24.04 11a
Number.prototype.pad = function(n)
{
// echo("******************************");
// echo("Function pad() n = " + n);
//
var l = Math.floor(this).toString().length;
if (l < n)
{
for (var i = 0; i < (n - l); i++)
{
this = "0" + this;
}
}
return this;
//
// echo("END of pad()");
// echo("..............................");
};
/*
num = 7;
trace(num.pad(2)); // 07
num = 100;
trace(num.pad(2)); // 100 - number length > n
num = 57;
trace(num.pad(2)); // 57 - number length == n
num = 525;
trace(num.pad(4)); // 0525
*/