PDA

View Full Version : Clock


larainthewest
07-28-2005, 02:41 PM
Hi there. Please could you help me - I'm trying to find the HTML code in order to display the time on my website. Is there an easy way to do this? Any help appreciated! Thanks, I'm in South Africa.

coothead
07-28-2005, 04:06 PM
Hi there larainthewest,

and a warm welcome to these forums. :)

Do you want something like this...
<!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">
<head>
<title>simple time and date</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<style type="text/css">
/*<![CDATA[*/

body {
background-color:#006;
}
#clock {
width: 400px;
margin: 50px auto;
}
#clock input {
width:400px;
font-family:verdana,arial,helvetica,sans-serif;
font-size:16px;
color:#fff;
text-align:center;
background-color:#006;
border:solid 1px #006;
}

/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[

function setClock() {
var today=new Date();
var clock=today.toLocaleString();
document.forms[0][0].value ="Today is " + clock;

setTimeout("setClock()",1000);
}

onload= setClock;

//]]>
</script>

</head>
<body>

<form action="#">
<div id="clock">
<input type="text"/>
</div>
</form>

</body>
</html>

larainthewest
07-30-2005, 08:46 AM
Thanks coothead! That's it - but I think it picks up the time from my computer and not GMT (+2) - in other words if someone else looks at the clock are they going to see what time it is in SA, or will it pick up the time on their pc? Thanks again.

RysChwith
08-01-2005, 08:25 AM
Any purely Javascript clock is going to be grabbing the local computer's time (meaning where the viewer is, not where you are). If you want it to always show the time in South Africa, you either need some way for the user to declare his time zone, and then have the script calculate from that, or you need to have the initial time calculated by server-side script and then start the clock from there (assuming your server is also in South Africa).

Rys