A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: New Problem with the AM/PM issue

  1. #1

    New Problem with the AM/PM issue

    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.

    Thank you in advance

    S
    Attached Files Attached Files

  2. #2
    Mike Haverstock
    Join Date
    Dec 2001
    Posts
    167

    instead of hour= hour+1..

    instead of hour=hour+1: it's just hour+=1;
    then you also want to make min=min-59 into min=min-60.. i have a working example..
    Attached Files Attached Files

  3. #3
    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?

    S

  4. #4
    Member
    Join Date
    Mar 2001
    Posts
    73
    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.

  5. #5

    Updated file attached

    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);
    Thx

    S
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    Mar 2001
    Posts
    73
    Oops... I screwed up...

    In the simplified if/else statement, I used 'hours' instead of 'hour'. If you change that it should take care of the problem.

  7. #7

    IT WORKS

    boltUpright->>>>>>>>>YOU ARE THE MAN

    What would I do without you

    Thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center