Use JavaScript to add a date to a Web page

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax client date example function javascript personal programming

We all know that using dreameaver to add time and date to a page, we use JavaScript today to implement this function, and to understand the role of JavaScript in the Web programming language, The principle of this example is to make the date and time of a personal client machine appear on the Web page through the execution of a JavaScript program.

The source program is as follows:

<script language= "LiveScript" ><br><br>
<br><br>
<!--hiding<br><br>
<br><br>
Today = new Date () <br><br>
<br><br>
document.write ("Welcome to 5D Multimedia:) The current time is ", Today.<a href=" http://www.jzread.com/tag/get/"target=" _blank ">get</a>hours (),": ",<br> <br>
<br><br>
Today.getminutes () <br><br>
<br><br>
document.write ("<br> Today's date is", Today.getmonth () +1,<br><br>
<br><br>
"/", Today.getdate (), "/", Today.getyear ());<br><br>
<br><br>
End Hiding contents--><br><br>
<br><br>
</script>

In this case, we must first establish a date variable, which can be done by today= new Date (). If no specific time and date are specified, the browser will take the local client machine time. If you put him 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 dates 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 be combined with time settings. The first three docstarted = new Date (96,0,13,10,50,0) are the year, month, day, and then the time, minute, and second of the date.

Finally, we have to remind you that JavaScript does not have a real date form, but he can display the date and time effortlessly, because he calculates the current time from the 1/1/1970 0 0h with MS (milli seconds), which may sound complicated. But you don't have to worry, he 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.