Home >Web Front-end >JS Tutorial >JS code to completely display the current date and time_time and date

JS code to completely display the current date and time_time and date

WBOY
WBOYOriginal
2016-05-16 19:09:031466browse

The code demonstration effect is "12:42:48 noon on Sunday, February 25, 2007".
How to use: Put the following JS code into the page you want to display (supports HTML pages), and then insert the following code where you want to display the time



The JS code is as follows:




<script> <BR>function tick() { <BR>var hours, minutes, seconds, xfile; <BR>var intHours, intMinutes, intSeconds; <BR>var today, theday; <BR>today = new Date(); <BR>function initArray(){ <BR>this.length=initArray.arguments.length <BR>for(var i=0;i<this.length;i++) <BR>this[i+1]=initArray.arguments[i] } <BR>var d=new initArray( <BR>"星期日", <BR>"星期一", <BR>"星期二", <BR>"星期三", <BR>"星期四", <BR>"星期五", <BR>"星期六"); <BR>theday = today.getYear()+"年" + [today.getMonth()+1]+"月" +today.getDate() + d[today.getDay()+1]; <BR>intHours = today.getHours(); <BR>intMinutes = today.getMinutes(); <BR>intSeconds = today.getSeconds(); <BR>if (intHours == 0) { <BR>hours = "12:"; <BR>xfile = "午夜"; <BR>} else if (intHours < 12) { <BR>hours = intHours+":"; <BR>xfile = "上午"; <BR>} else if (intHours == 12) { <BR>hours = "12:"; <BR>xfile = "正午"; <BR>} else { <BR>intHours = intHours - 12 <BR>hours = intHours + ":"; <BR>xfile = "下午"; <BR>} <BR>if (intMinutes < 10) { <BR>minutes = "0"+intMinutes+":"; <BR>} else { <BR>minutes = intMinutes+":"; <BR>} <BR>if (intSeconds < 10) { <BR>seconds = "0"+intSeconds+" "; <BR>} else { <BR>seconds = intSeconds+" "; <BR>} <BR>timeString = theday+xfile+hours+minutes+seconds; <BR>Clock.innerHTML = timeString; <BR>window.setTimeout("tick();", 100); <BR>} <BR>window.onload = tick; <BR></script> A more practical code worth collecting ^_^
Statement:
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