Home > Web Front-end > JS Tutorial > Sample code for dynamically displaying time changes on a javascript page_javascript skills

Sample code for dynamically displaying time changes on a javascript page_javascript skills

WBOY
Release: 2016-05-16 17:08:33
Original
1124 people have browsed it
Copy code The code is as follows:



< ;title>

<script> <br>function getDateDemo(){ <br>/* <br><br>//Declaration time<br>var date = new Date( ); <br>alert(date);//Current time<br>alert(date.toLocaleString());//Convert to local time<br>alert(date.getFullYear());//Display year<br>alert(date.getMonth() 1);//Display month 0-11, need to add 1 <br>alert(date.getDate());//Display the date in January <br>alert(date.getDay ());//Display the date of the week, day of the week<br>alert(date.getHours());//Get the hour time<br>alert(date.getMinutes());//Get the current minutes<br> alert(date.getSeconds());//Get the current number of seconds<br>alert(date.getMilliseconds());//Get the current number of milliseconds<br>alert(date.getTime());//Get from At midnight on January 1, 1970, the millisecond value to the current time <br>*/ <br>//Get the year, month, day, hour, minute, and second respectively <br>var myDate = new Date(); <br>var year = myDate.getFullYear(); <br>var month = myDate.getMonth() 1; <br>var date = myDate.getDate(); <br>var hours = myDate.getHours(); <br>var minutes = myDate.getMinutes(); <br>var seconds = myDate.getSeconds(); <br><br>//The month is displayed as two digits such as September <br>if(month < 10 ){ <BR>month = "0" month; <BR>} <BR>if(date < 10 ){ <BR>date = "0" date; <BR>} <br><br>//Time Splice <BR>var dateTime = year "year" month "month" date "day" hours "hour" minutes "minute" seconds "second"; <br><br>//document.write(dateTime);//print Current time<br><br>var divNode = document.getElementById("time"); <BR>divNode.innerHTML = dateTime; <br><br>} <BR>window.setInterval("getDateDemo()",1000 );//Every second, call getDateDemo() <BR></script>





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template