Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Write Time

  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Write Time

    How can you write the time every second. I am using document.write but it wipes out the previous time. I want as each second pass, the next time will be on the next line.

    Thanks

    I don't know what to search on this one.

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Sydney, NSW, Australia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The easiest way would be to update a form element every second, otherwise you'll need to use dynamic layers.

    Alternatively you could download a pre-made time script from javascriptkit or dynamicdrive.

    - Mark

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <div id="clock">8:88</div>
    <script type="text/javascript">
    var clk=document.getElementById("clock").firstChild;
    
    function time() {
    var minutes=new Date().getMinutes();
    var hours=new Date().getHours();
    var seconds=new Date().getSeconds();
    if(hours<12) hours-=12;
    
    clk.nodeValue=hours+":"+minutes+:":"+seconds;
    setTimeout(time,1000);
    } time();
    </script>

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Plano, Texas
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I gave a sample script that does just that on a previous post. Refer to:

    http://www.codingforums.com/showthre...?threadid=2551

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks for your replies!!!

    nolachrymose, your script gave me an error.


    JoeP, does your script keep the previous content? I was looking for something that writes the new time out on a new line every second. It will keep the previous content.

    Mark, I will look into that.

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Something like this!

    I just can't get the scroll to work but something like this.

    Code:
    		<script language="JavaScript">
    			var T = window.open("",'Window_ID','menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=no');
    			T.resizeTo(200,200);
    			T.moveTo((screen.width - 200)/2,(screen.height - 200)/2);
    
    			var timerID = null
    			var	timerRunning = false
    			function stopclock()
    			{
    				if(timerRunning)
    					clearInterval(timerID)
    					timerRunning = false
    			}
    			function startclock()
    			{
    				// Make sure the clock is stopped
    				stopclock()
    				timerID = window.setInterval("showtime()",1000)
    				timerRunning = true
    			}
    			function showtime()
    			{
    				var now = new Date()
    				var hours = now.getHours()
    				var minutes = now.getMinutes()
    				var seconds = now.getSeconds()
    				var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    				timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    				timeValue += ((seconds < 10) ? ":0" : ":") + seconds
    				timeValue += (hours >= 12) ? " P.M." : " A.M."
    				//top.Right_Area.document.writeln(timeValue + '<br>');
    
    				if (T.closed)
    				{
    					clearInterval(timerID);
    				}
    				else
    				{
    					T.document.writeln(timeValue + '<br>');
    					//T.scrollBy(0, 30);
    					T.focus();
    				}
    			}
    		</script>

  • #7
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you please tell me what is the point in bringing posts TTT which were resolved over six monthes ago?

    .....Willy

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Look at the date again... over 1 year and 6 months


  •  

    Posting Permissions

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