Add date to page using JavaScript
Author:Eve Cole
Update Time:2009-05-31 21:04:14
Many netizens will find that many web pages have the function of displaying time and date when browsing the web. This is not difficult. You can directly insert time and date using the visual web page production software Dreameaver. But today we use JavaScript to implement this function, and at the same time it can play a role in understanding the network programming language JavaScript. The principle of this example is to display the date and time of the personal client machine on the web page through the execution of the JavaScript program.
The source program is as follows:
In this example, we must first create a date variable, which can be done with today= new Date(). If no time and date are specified, the browser will use the time of the local client machine. If we put it into the variable today, what should be noted here is that we did not declare the type of today variable.
In addition to the above functions, when creating a date object, you can also set the date in advance as follows:
docStarted= new Date(96,0,13)
First is the year, then the month (but remember to subtract 1), then the day. You can also add time settings in the same way. As follows docStarted = new Date(96,0,13,10,50,0) The first three are the year, month, and day of the date, followed by the hour, minute, and second.
Finally, we must remind you that JavaScript does not have an actual date type, but it can display dates and times effortlessly because it is calculated in ms (milli seconds) starting from 1 / 1/ 1970 0 0h At this time, this may sound complicated. But you don't have to worry, it has standard shared functions for calculation, you just need to know how to use them.