JavaScript
Time and Date in Status Bar
Back


Displays time and date in browsers status bar

There are two parts to this script. The part 1 code is the start() and stop() functions that are placed in the first body tag of your document. Part 2 is placed between the head tags of your document.


Place part 1 code after the BODY in your documents first body tag.
Part 1 Example:

<BODY ONLOAD="start()" ONUNLOAD="stop()">

Part 1 Code:

ONLOAD="start()" ONUNLOAD="stop()"



Place part 2 code between the HEAD tags of your document.
Part 2 Example:

<HEAD> Place part 2 code here</HEAD>

Part 2 Code:

 <SCRIPT LANGUAGE="Javascript">
<!--Hiding the code
 var show_time=false;
 var timerID=null;
 function stop(){
    if (show_time){
        clearTimeout(timerID);
        document.status =" ";
    }
    show_time=false;
 }

 function start(){
var display_value = " ";
var today=new Date();
	if(today.getHours()>12){
    display_value +=(today.getHours() - 12);
}else {
display_value += today.getHours();
}
    if(today.getMinutes() < 10){ 
       display_value+=":0" + today.getMinutes();
    }
   else{
       display_value+=":" + today.getMinutes();
    }
    if (today.getSeconds() < 10){
       display_value+=":0" + today.getSeconds();
    }
    else{
       display_value+=":" + today.getSeconds();
    }
    if(today.getHours()>=12){
       display_value+=" PM" 
    }
    else{
       display_value+=" AM"
    } 
    display_value += "  " + (today.getMonth()+1) + "/"  +
       today.getDate() + "/" + today.getYear();
 window.status =display_value;
       timerID=setTimeout("start()",100);
       show_time=true;
 }
 //done hiding-->
</SCRIPT>
 


Rate this script
Excellent Acceptable Poor
Comment: