chirag.khatri
05-15-2009, 12:44 PM
1) CODE TITLE: Display Current Time with JS
2) AUTHOR NAME/NOTES: Chirag S Khatri
3) DESCRIPTION: This script shows the current time continues on your webpage without refreshing the page.
4) URL TO CODE:
<script type="text/javascript">
<!-- Put the following code in your JS file or Head Tags ---->
<!--
function DisplayTime(){
if (!document.all && !document.getElementById)
return
timeElement=document.getElementById? document.getElementById("curTime"): document.all.tick2
var CurrentDate=new Date()
var hours=CurrentDate.getHours()
var minutes=CurrentDate.getMinutes()
var seconds=CurrentDate.getSeconds()
var DayNight="PM"
if (hours<12) DayNight="AM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var currentTime=hours+":"+minutes+":"+seconds+" "+DayNight;
timeElement.innerHTML="<font style='font-family:verdana, arial,tahoma;font-size:12px;color:#E25984; font-weight:bold;'>"+currentTime+"</b>"
setTimeout("DisplayTime()",1000)
}
window.onload=DisplayTime
</script>
// -->
<!-- Put the following code in your web page where you want to show the time ---->
<span id=curTime></span>
View Demo (http://www.freewebs.com/khatrichirag/currenttimewithjs.htm)
or, ATTACHED BELOW (see #3 in guidelines below):
2) AUTHOR NAME/NOTES: Chirag S Khatri
3) DESCRIPTION: This script shows the current time continues on your webpage without refreshing the page.
4) URL TO CODE:
<script type="text/javascript">
<!-- Put the following code in your JS file or Head Tags ---->
<!--
function DisplayTime(){
if (!document.all && !document.getElementById)
return
timeElement=document.getElementById? document.getElementById("curTime"): document.all.tick2
var CurrentDate=new Date()
var hours=CurrentDate.getHours()
var minutes=CurrentDate.getMinutes()
var seconds=CurrentDate.getSeconds()
var DayNight="PM"
if (hours<12) DayNight="AM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var currentTime=hours+":"+minutes+":"+seconds+" "+DayNight;
timeElement.innerHTML="<font style='font-family:verdana, arial,tahoma;font-size:12px;color:#E25984; font-weight:bold;'>"+currentTime+"</b>"
setTimeout("DisplayTime()",1000)
}
window.onload=DisplayTime
</script>
// -->
<!-- Put the following code in your web page where you want to show the time ---->
<span id=curTime></span>
View Demo (http://www.freewebs.com/khatrichirag/currenttimewithjs.htm)
or, ATTACHED BELOW (see #3 in guidelines below):