www.webdeveloper.com
Results 1 to 3 of 3

Thread: time in innerHTML

  1. #1
    Join Date
    Feb 2011
    Posts
    49

    time in innerHTML

    i'm trying to get the time to post in a innerhtml and don't why it isn't working.

    i tried remove the script having it septate and still nothing.

    help please.

    thanks


    Code:
                         Time.innerHTML =
                         "&nbsp;<span title='TimeStamp()'>T</span>"+"&nbsp;&nbsp;<span>OV</span>";
                         "<script type='text/javascript'>\n"
                         +"function timestamp() {\n"
                         +"var currentTime = new Date()\n"
                         +"var hours = currentTime.getHours()\n"
                         +"var minutes = currentTime.getMinutes()\n"
                         +"if (minutes < 10){\n"
                         +"minutes = '0' + minutes\n"
                         +"}\n"
                         +"hours + ':' + minutes + ' '\n"
                         +"if(hours > 11){\n"
                         +"document.write('PM')\n"
                         +"} else {\n"
                         +"document.write('AM')\n"
                         +"}\n"
                         +"}\n"
                         +"< /script>\n";

  2. #2
    Join Date
    Mar 2011
    Posts
    81
    Count this example work?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">//<![CDATA[
    var digital = new Date()
    function clock() {
    if (!document.all &&!document.getElementById) return;
    var hours = digital.getHours();
    var minutes = digital.getMinutes();
    var seconds = digital.getSeconds();
    digital.setSeconds( seconds+1 );
    if (hours <= 9) hours = "0" + hours;
    if (minutes <= 9) minutes = "0" + minutes;
    if (seconds <= 9) seconds = "0" + seconds;
    dispTime = hours + ":" + minutes + ":" + seconds;
    if (document.getElementById)
    document.getElementById("TIME").innerHTML = dispTime
    else if (document.all)
    time.innerhtml = dispTime;
    setTimeout("clock()", 1000);
    }
    //]]></script>
    </head>
    <body onload="clock();">
    <div id="TIME">
    </div>
    </body>
    </html>

  3. #3
    Join Date
    Apr 2011
    Location
    I live in the pinaple under the sea
    Posts
    107
    try this...
    HTML Code:
    <html>
    <head>
    <title>Javascript Time</title>
    <script type="text/javascript">
    var timerID = null;
    
    function showTime(){
        var objTimer = new Date();
        var tHour = objTimer.getHours();
        var tMin = objTimer.getMinutes().toString();
        var tSec = objTimer.getSeconds().toString();
        var ap = "AM";
        
        if(tHour > 11)
            ap = "PM";
        
        if(tHour > 12)
            tHour = tHour - 12;
        
        if(tHour == 0)
            tHour = 12;
            
        if(tMin.length == 1)
            tMin = "0" + tMin;
    
        if(tSec.length == 1)
            tSec = "0" + tSec;
        
        document.getElementById("timer").innerHTML = tHour + ":" + tMin + ":" + tSec + " " + ap;
        
        timerID = setTimeout("showTime()", 100);
    }
    
    window.onload = showTime;
    </script>
    </head>
    <body>
    <div id="timer"></div>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles