View Full Version : Date in Javascript

19 Aug 2010, 03:24 PM
Just been playing about with a website I've been designing and thought I would share how to represent the date in Javascript.

The way I design websites is to use external documents so create a new document entitled "date.js" then copy and paste:

var today = new Date()
var monthnum = today.getMonth()
var monthname=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
var day = today.getDate()
var year = today.getFullYear()
document.write(day + " " + monthname[monthnum] + " " + year)

You can play about with how the date is represented in the "document.write" entry (if you're not complete au fait with Javascript).

Once this has been saved, you can the import it to your HTML document by copy and pasting this:

<script src="date.js"></script>

And you should then have a working date counter on your website :)