Quote:
Originally Posted by agarwalsunitadhn
hi....
i want to display current date and time of client side in the page. i have the javascript code also bt i dnt know how to use it in the page. the code is
-
function ShowTime()
-
{
-
var TimerKey
-
var now = new Date()
-
var Hours = now.getHours()
-
var Minutes = now.getMinutes()
-
var Seconds = now.getSeconds()
-
TimeDisplay.innerText = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
-
window.status = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
-
TimerKey = setTimeout("ShowTime()",1000)
-
}
-
name of the file is showtime.js
please give me the instruction to use it
In your HTML HEAD section.
include the JS file using
<script src="filename.js"></script>
Also somewhere you should define what "TimerDisplay" is...
Let us say there is a div as shown ..
<div id="timer"></div>
within head ....
<script>
startShowingTime()
{
TimerDisplay = document.getElementById("timer");
ShowTime();
}
</script>
Again, I am not a scripting expert. But you can use something like setTimeOut() event to periodically invoke ShowTime()