|
-
Mar 9th, 2004, 06:40 PM
#1
Thread Starter
Fanatic Member
Dynamic clock?
I am trying to make a clock that ticks in the status bar. It displays the correct time, but it doesn't update every second. What is wrong with the code?
PHP Code:
<html>
<head>
<title>Clock</title>
<script>
var today = new Date();
var hours;
var minutes;
var seconds;
var ampm;
var total;
function updateTimer()
{
hours = today.getHours();
minutes = today.getMinutes();
seconds = today.getSeconds();
ampm = "AM";
if (hours >= 12)
ampm = "PM";
if (hours >= 12)
hours -= 12;
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
total = hours + ":" + minutes + ":" + seconds + " " + ampm;
window.status = total;
setTimeout("updateTimer()", 1000);
}
</script>
</head>
<body onLoad="updateTimer()">
</body>
</html>
Alcohol & calculus don't mix.
Never drink & derive.
-
Mar 9th, 2004, 06:54 PM
#2
Frenzied Member
Code:
<html>
<head>
<title>Clock</title>
<script>
var today = new Date();
var hours;
var minutes;
var seconds;
var ampm;
var total;
function updateTimer()
{
hours = today.getHours();
minutes = today.getMinutes();
seconds = today.getSeconds();
ampm = "AM";
if (hours >= 12)
{
ampm = "PM";
hours -= 12;
}
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
total = hours + ":" + minutes + ":" + seconds + " " + ampm;
window.status = total;
}
setInterval("updateTimer()",1000)
</script>
</head>
<body>
</body>
</html>
Have I helped you? Please Rate my posts. 
-
Mar 9th, 2004, 07:02 PM
#3
Thread Starter
Fanatic Member
Still not working. I've tested in IE6 and Firefox 0.8. It displays it the one time, then just sits there.
Alcohol & calculus don't mix.
Never drink & derive.
-
Mar 9th, 2004, 07:11 PM
#4
Frenzied Member
now it works
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Dynamic Clock</title>
<script type="text/javascript">
function updateTimer()
{
var today = new Date();
var hours;
var minutes;
var seconds;
var ampm;
var total;
hours = today.getHours();
minutes = today.getMinutes();
seconds = today.getSeconds();
ampm = "AM";
if (hours >= 12)
{
ampm = "PM";
hours -= 12;
}
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
total = hours + ":" + minutes + ":" + seconds + " " + ampm;
window.status = total;
}
</script>
</head>
<body onLoad="setInterval('updateTimer()','1000')">
<p>It wasn't working because Date() has to be included with the function so it is also updates constantly. Otherwise you are only using
the date (the time) from when the page loaded over and over again.</p>
</body>
</html>
Have I helped you? Please Rate my posts. 
-
Mar 10th, 2004, 01:29 AM
#5
Thread Starter
Fanatic Member
Ok thanks, that makes sense
Alcohol & calculus don't mix.
Never drink & derive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|