When browsing a Web page, many netizens may find that many web pages have the function of displaying time and date. This is not difficult. The visual web page creation software Dreameaver can be used to directly insert time and date. However, today, we use JavaScript to implement this function and understand the WEB programming language JavaScript, the principle of this example is to display the date and time of the personal client machine on the webpage through the execution of JavaScript programs.
The source code is as follows:
<Script language = "LiveScript"> <br>
<Br>
<! -- Hiding <br>
<Br>
Today = new Date () <br>
<Br>
Document. write ("Welcome to 5D multimedia :) the current time is", today. getHours (), ":", <br>
<Br>
Today. getMinutes () <br>
<Br>
Document. write ("<br> today's date is", today. getMonth () + 1, <br>
<Br>
"/", Today. getDate (), "/", today. getYear (); <br>
<Br>
// End hiding contents --> <br>
<Br>
In this example, we must first create a Date variable, which can be completed by today = new Date. If no special time or date is specified, the browser uses the Time of the local client machine. If you put it in the today variable, note that we have not declared the type of the today variable.
In addition to the preceding functions, you can set the date as follows when creating a date object:
DocStarted = new Date (96,0, 13)
The first is the year, followed by the month (but remember to subtract 1), followed by the day. You can add time settings in the same way. The first three docStarted = new Date (,) are the year, month, and day of the Date, followed by hour, minute, and second.
Finally, we must remind you that JavaScript does not have an actual date type, but it can display the date and time effortlessly, the reason is that it was calculated from 1/1/1970 0 0 h with a MS (milli seconds) for the current time, which sounds a bit complicated. But you don't have to worry about it. It has standard shared functions for computing. You only need to know how to use them.