Welcome to W3Courses

Automatically Display the Current or Today's Date with JavaScript

Add the following code to your html page where you want today's date to be displayed automatically

<script>
<!-- //Hide From Old Browsers

/*
   Do Not Remove the Following Line
   For more scripts visit http://www.w3courses.com
*/

var d=new Date();
var y=d.getYear();
if (y < 1000)
     y+=1900;
var day=d.getDay();
var m=d.getMonth();
var daym=d.getDate();
if (daym<10)
     daym="0"+daym;
var mon=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.write("<font size='2' color='red'>"+mon[m]+" "+daym+", "+y+"</font>");

// End Hide -->
</script>
 

No votes yet