myDate = new Date();Note that the case is important. The correct spelling of Date start with a capital D. You can next display the date using:
document.write (myDate);Following is a simple code that displays a textbox alongwith an associated button. When you click the button, the contents of the new Date() appear in the textbox.
Associate Properties and MethodsWe can summarize the methods available with the date object in the following table. Their use will be explained in the next section, i.e. Creatively Using the Date.
Date() Returns a new date object getDate() Returns a date from the date object (0-31) getDay() Returns the day of the week (0-6) getMonth() Returns the month (0-11) getFullYear() Returns the year (2000) getHours() Returns the hour (0-23) getMinutes() Returns the minute (0-59) getSeconds() Returns the seconds (0-59)
Creatively Using the DateWe will now do a simple example that will explain how we can display time on a web page. To understand the code you should have concepts of setTimeOut(). It was explained in my last article; go there if you don’t have the concept and have difficulty in comprehending the following code.