Displaying current month
I want a script that will display the current month and year.
e.g. April 2007
Start by creating a Date object. Then use the getMonth and the getFullYear to get what you need.
Note that getMonth return a number and not the month name. Number will be 0 to 11. Meaning that you will have to create an Array with the month names to be able to output the name.
You will need to store an object that contains the month names-
ideally this would be a language dependent object, but I'll stick to English:
I like to attach a monthnames array, when needed, to the Date object,
but you can attach it to the window, or any object you like:
Then you can generate the current date and return the month from the array and the year from getFullYear():
var D=new Date();
var str= Date.monthnames[D.getMonth()]+' '+D.getFullYear();