This only happens when your time on your PC is 4:55 or 9:55 to the hour 10:00. I have this banner with 2 time desplays, one is current time and the 2nd is +5min. The 2nd value desplays wront when the time is 4:55. It looks like 41:00 insted of 5:00. It has somethig to do with the following "if else" statement but I can not figure out what it is.
code:
if (min>59) {
hour = hour +1;
min = min - 59;
}
If you try to debug this make sure you reset the clock to :55. I am attachinbg the final FLA.
The same prooblem still presists. But only on PM time not AM. For instance if you set your PC clock to 4:56 you will see that the second desplay shows 41:01 instead of 5:01, what could cause that?
I don't have a ton of time to look at this right now, but right off hand I would say the problem is coming from the way you are setting the hour values. All those if/else statements set the hour to a string value instead of a number. Adding + 1 to a string with a value of 4 makes it 41 instead of 5 because Flash treats "4" as a word and adds the 1 to the end of the "word".
Additionally, your lines of if/else statements can be simplified down to just:
Code:
if(hours > 12){
hours -= 12
}
if (hours == 0){ // I'm not sure if 12 midnight is 24 or 0 in Flash.
hours = 12 // If it's 24, the first one will catch it and this
} // can be eliminated.
I think all your code will work ok, just remember not to quote the number values you assign.
Ok this code seems to have fixed that issue with the (41) but now I get MILITARY time format and I need US format (4:58:23 PM). I dont know how to acheave that, if somone could assist me I would greatly appriciate that.
Code:
function writeTimeLong(format) {
d = new Date();
dh = d.getHours()
if (dh >= 12) {
ttt="PM";
} else {
ttt="AM";
}
hour = d.getHours();
min = d.getMinutes();
sec = d.getSeconds();
//NONE MILITARY TIME
if(hours > 12){
hours -= 12
}
if (hours == 0){ // I'm not sure if 12 midnight is 24 or 0 in Flash.
hours = 12 // If it's 24, the first one will catch it and this
} // can be eliminated.
if (min>59) {
hour +=1;
min = min - 60;
}
if (hour<10) {
hour = ""+hour;
}
if (min<10) {
min = "0"+min;
}
if (sec<10) {
sec = "0"+sec;
}
if (format == 0) {
str = hour+":"+min+":"+sec+" "+ttt;
} else if (format == 1) {
str = hour+":"+min+" "+ttt;
}
return (str);
}
function writeTime() {
writeTimeLong(0);
}
timeCont = writeTimeLong(0);