PDA

View Full Version : Displaying time, and refreshing



djr33
05-30-2006, 08:37 PM
My friend wants the time on his page... this is a really easy script... I just don't know the syntax.

Here's what he had originally:



<style type="text/css">
span.bigtext {
font-size: 150%;
}
</style>
...
</head><body>
...
<div>
<SCRIPT>
document.write("<span class=\"bigtext\">"+Date()+".</span>");
</SCRIPT>
</div>


that works just fine... shows the time, and date and such.

However... two things:

1. He doesn't want military time... is this some attribute of the function?

2. He wants it to refresh...
I tried messing with making it a recursive function and using "delay 1000", but couldn't get the syntax right... what I know of JS is just what I've seen in passing.


Should be easy for those who know :)

thanks.

Btw, feel free to change it however you want... the script above is just a starting point. And, yeah, he wants to be able to control the size of the font in css.

Twey
05-30-2006, 08:49 PM
Head:
<style type="text/css">
#time {
font-size: 150%;
}
</style>

<script type="text/javascript">
function updateTime() {
var d = new Date();
document.getElementById("time").innerHTML = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}
window.onload = function() { updateTime(); window.setInterval(updateTime, 1000); };
</script>Body:
<span id="time"></span>

djr33
05-31-2006, 12:41 AM
thanks :)

already passed it along to my friend in the web design class.

he'll be happy.