Add a date to the page with JavaScript

Source: Internet
Author: User
Tags current time time and date

Many netizens should find that many Web pages have the function of displaying time and date when browsing the Web page, which is not difficult, and can be directly inserted into time and date by using Visual Web Dreameaver software. 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:

<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:) Now time is ", today.gethours (),": ",<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>

  

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 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 = 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 an actual date form, but it can display the date and time effortlessly, since it 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, it has a standard common function to calculate, you just know how to use it.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.