...

View Full Version : Write local time to page



ChrisCapps
06-25-2002, 10:58 AM
Hi,

How can I modify this script so that the local time shows on my home page at load, with no button- or link-clicking necessary? In other words, I want my local time to write automatically on my home page at load, but I don't want it in a separate alert box/window.

I tried changing "alert" in the function to "document.write" and calling the function in the body, and it does write, but ON A TOTALLY SEPARATE PAGE from my home page. If I keep the "alert" as-is, and call the function in the body, the time writes in an alert window. Again, not what I want. Any ideas?

<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- 540 from 9*60 because I'm in South Korea, which is GMT+8 and DST -->
<!-- Begin
function showlocaltime() {
var today = new Date();
var difftime = (today.getTimezoneOffset()+540) *60000;
today.setTime(today.getTime()+difftime);
alert(today.toLocaleString());
}
// End -->
</script>

</head>

<body>

<div align="center">
Click <a href="javascript:showlocaltime()">[here]</a> to find the current local time.
</div>

joh6nn
06-25-2002, 11:29 AM
<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- 540 from 9*60 because I'm in South Korea, which is GMT+8 and DST -->
<!-- Begin
function showlocaltime() {
var today = new Date();
var difftime = (today.getTimezoneOffset()+540) *60000;
today.setTime(today.getTime()+difftime);

}
// End -->
</script>

</head>

<body>

<script>
document.write(today.toLocaleString());
</script>

</body>

ChrisCapps
06-25-2002, 11:40 AM
Thanks for your help.

When I tried this, I got an error saying "today" was undefined. Any other ideas?

joh6nn
06-25-2002, 11:52 AM
whoops, sorry, didn't take a close enough look at the code.

<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- 540 from 9*60 because I'm in South Korea, which is GMT+8 and DST -->
<!-- Begin
function showlocaltime() {
var today = new Date();
var difftime = (today.getTimezoneOffset()+540) *60000;
today.setTime(today.getTime()+difftime);
return today.toLocaleString();
}
// End -->
</script>

</head>

<body>

<script>
document.write(showlocaltime());
</script>

</body>

ChrisCapps
06-25-2002, 12:17 PM
Hey,

All is well. Thanks much. I've been beating my head against the wall for weeks trying to figure this out.

Thanks for your time, energy and willingness to share your knowledge.

joh6nn
06-25-2002, 12:33 PM
not a problem.

and good luck for today's game.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum