Putting the Current Date into a Web Page

JavaScript can determine the current date and time from your computer (which it gets as a number) and then manipulate that figure in many ways. Your script has to handle the conversion from a number the computer uses into a textual date you can understand, however. Script 12.1 shows how to get the current date, convert it from a number into a standard date, and then write the result to a document window.

To put the current date into a Web page:

1.
window.onload = initDate;
When the document loads, call initDate().
2.
var dayName = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
First, we need to create a new array that contains the days of the week. Make sure to ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.