...

View Full Version : Write Time



Hawk
07-25-2002, 03:05 AM
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.

Astro-Boy
07-25-2002, 03:37 AM
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 (http://www.javascriptkit.com) or dynamicdrive (http://www.dynamicdrive.com).

- Mark

nolachrymose
07-25-2002, 01:58 PM
<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>

JoeP
07-25-2002, 03:05 PM
I gave a sample script that does just that on a previous post. Refer to:

http://www.codingforums.com/showthread.php?threadid=2551

Hawk
07-25-2002, 06:36 PM
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.

Hawk
07-25-2002, 08:04 PM
I just can't get the scroll to work but something like this.



<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>

oldcrazylegs
02-28-2004, 06:13 PM
http://javascript.about.com/library/tools/bldocwriter.htm

Willy Duitt
02-28-2004, 06:31 PM
Could you please tell me what is the point in bringing posts TTT which were resolved over six monthes ago?

.....Willy

Nightfire
02-28-2004, 07:02 PM
Look at the date again... over 1 year and 6 months:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum