Add a date to the page using JavaScript

Source: Internet
Author: User
Tags add time

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.