ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

String Formatting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • String Formatting

    Hey - I am trying to make a simple Java timer, which I have done. But it is displaying the hrs/mins/secs as is - ie if it is less than 10 secs it is displaying say "7", While I want it to display "07".

    Can anyone advise a simple 1 line format option ?
    The .value is actually coming back undefined so it is always hitting the else condition.

    PHP Code:
    code -deleted see copy below ... 
    Thx - GC
    Last edited by gcraill; May 8, 2007, 05:50 AM. Reason: redundant code snippet
    Greg Craill: "Life's hard - Get a helmet !!"

  • #2
    Re: Colors in Java

    Ok got that one sorted ...

    Next question - The following code works, but I would like to be able to change the font colour to red when an even has expired.
    Any suggestions ?

    PHP Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <form name="count">
    <table border=1>

    <?php
    for ($game=1;$game<6;$game++)
    {
        
    $py=2007$pm=5$pd=7+$game$phr=13+$game$pmn=0+($game*10);
        
    $gtxt="Event number $game"
        
    $gblah="$py/$pm/$pd $phr:$pmn";
        print 
    "<tr><td>$gtxt</td><td>$gblah</td><td><input type='text' size='35' name='timer$game'></td></tr>";

    print 
    "<script>
        var before='Next Event Closes in '
        var current='Event Closed!'
        var montharray=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
        function countdown
    $game(yr,m,d,hr,mn)
        {    ty
    $game=yr;tm$game=m;td$game=d;thr$game=hr;tmn$game=mn
            var today=new Date()
            var todayy=today.getYear()
            if (todayy < 1000) todayy+=1900
            var todaym=today.getMonth()
            var todayd=today.getDate()
            var todayh=today.getHours()
            var todaymin=today.getMinutes()
            var todaysec=today.getSeconds()
            var todaystring=montharray[todaym]+' '+todayd+', '+todayy+' '+todayh+':'+todaymin+':'+todaysec
            futurestring=montharray[m-1]+' '+d+', '+yr+' '+hr+':'+mn+':00'
            dd=Date.parse(futurestring)-Date.parse(todaystring)
            dday=Math.floor(dd/(60*60*1000*24)*1)
            dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
            dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
            dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
            if(dday+dhour+dmin+dsec<=0)
            {    document.forms.count.timer
    $game.value=current
                return    }
            else
            {    if(dday>0)    document.forms.count.timer
    $game.value=before+dday+' days, '
                else        document.forms.count.timer
    $game.value=before
                if(dhour<10) {xh
    $game='0'+dhour} else {xh$game=dhour}
                if(dmin<10)  {xm
    $game='0'+dmin}   else {xm$game=dmin}
                if(dsec<10)  {xs
    $game='0'+dsec}   else {xs$game=dsec}
                document.forms.count.timer
    $game.value += xh$game+':'+xm$game+':'+xs$game
            }
            setTimeout('countdown
    $game(ty$game,tm$game,td$game,thr$game,tmn$game)',1000)
        }
        countdown
    $game($py,$pm,$pd,$phr,$pmn)
    </script>"
    ;
    }
    ?>
    </table>
    </form>
    </body>
    </html>
    Greg Craill: "Life's hard - Get a helmet !!"

    Comment


    • #3
      Re: String Formatting

      Hmmm, that doesnt look like java code to me. You might get more hits if you post your question in the cgidev forum.
      Predictions are usually difficult, especially about the future. ~Yogi Berra

      Vertical Software Systems
      VSS.biz

      Comment


      • #4
        Re: String Formatting

        Originally posted by kpmac View Post
        Hmmm, that doesnt look like java code to me. You might get more hits if you post your question in the cgidev forum.
        - @#%@#%@#%@#%, I don't know any Java so i wouldn't have spotted that, I grabbed the function for the countdown timer from a Java tutorial site, added the hours and minutes for the target event, and then wrapped it in a php script so I can call it recursively for multiple events.

        I'll keep googling the net for possible answers anyway ... ?
        Greg Craill: "Life's hard - Get a helmet !!"

        Comment

        Working...
        X