Displaying the Date on Your Web Page



Here's a little script that will put the current date on your web page. Just stick this code anywhere on your page, and the date will appear right there.

<SCRIPT LANGUAGE="JavaScript"><!--
t=new Date();
var d=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var m=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.write(d[t.getDay()]+", "+m[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear());
-->
</SCRIPT>


If you want to place the date on multiple parts of your page, it's more efficient to use the script only once, and call a much smaller script each time you want the date.

Put this code in the <HEAD> section of your web page:

<SCRIPT LANGUAGE="JavaScript"><!--
curtime=new Date();
var days=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
function writeDate() {
    document.write(days[curtime.getDay()]+", "+months[curtime.getMonth()]+" "+curtime.getDate()+", "+curtime.getFullYear());
}
-->
</SCRIPT>

And then, when you want to show the date, use this code:

<SCRIPT LANGUAGE="JavaScript"><!--
writeDate();
-->
</SCRIPT>

 

Return to the JavaScript page
Visit Zioth.com