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;
}
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;
}