Add a date to the page with JavaScript (figure)

Source: Internet
Author: User
Tags add date current time variable time and date client
Javascript| page Many netizens should find that many Web pages have the function of displaying time and date, this is not difficult, using Visual Web-making software dreameaver can insert time and date directly. But today we use JavaScript to do this, and to understand the role of JavaScript in the Web programming language, the principle of which is to display the date and time of a personal client machine on a Web page through the execution of a JavaScript program.


The source program is as follows:

In this case, we must first establish a date variable, which can be done by today=newdate (). If no specific time and date are specified, the browser will take the time of the local client machine. If you put it in the variable today, notice here that we don't declare the form of today's variable.

In addition to the above features, you can set date objects in advance by setting the date as follows:

docstarted= new Date (96,0,13)

First is the year, then the month (but remember minus 1), then the day. The same method can also be combined with time settings. The first three docstarted =newdate (96,0,13,10,50,0) are the year, month, and day of the date, followed by time, minutes, and seconds.

Finally, we have to remind you that JavaScript does not have an actual date form, but it can display the date and time effortlessly, since it calculates the current time from 1/1/1970 0 0h with MS (milliseconds), which may sound complicated. But you don't have to worry, it has a standard common function to calculate, you just know how to use it.


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.