Page front desk display
The code copy is as follows:
<span id="clock" style="font-size:14px;"></span>
js script
The code copy is as follows:
$(document).ready(function () {
//The first type
showTime();
//The second type
var clock = new Clock();
clock.display($("#clock"));
});
//The first method of processing the current time of the system is displayed
function showTime() {
var myArray = new Array(7);
var TD = new Date();
myArray[0] = "Sunday";
myArray[1] = "Monday";
myArray[2] = "Tuesday";
myArray[3] = "Wednesday";
myArray[4] = "Thursday";
myArray[5] = "Friday";
myArray[6] = "Saturday";
weekday = TD.getDay();
var h = TD.getHours();
var m = TD.getMinutes();
var s = TD.getSeconds();
var hstr = h;
var mstr = m;
var isr = s;
if (h < 10) { hstr = "0" + h };
if (m < 10) { mstr = "0" + m };
if (s < 10) { isr = "0" + s };
$("#clock").innerHTML('Current time:' + new Date().toLocaleDateString() + " " + myArray[weekday] + " " + hstr + ":" + mstr + ":" + isr) ;
setTimeout(showTime, 1000);
}
//The second method of processing the current time of the system is displayed
function Clock() {
var date = new Date();
this.year=date.getFullYear();
this.month=date.getMonth()+1;
this.date=date.getDate();
this.day=newArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")[date.getDay()];
this.hour=date.getHours()<10?"0"+date.getHours():date.getHours();
this.minute=date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes();
this.second=date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds();
this.toString=function(){
return "The current time is:"+this.year+"year"+this.month+"month"+this.date+"day"+this.hour+":"+this.minute+":"+this.second+""+this .day;
};
this.toSimpleDate=function(){
returnthis.year+"-"+this.month+"-"+this.date;
};
this.toDetailDate=function(){
returnthis.year+"-"+this.month+"-"+this.date+""+this.hour+":"+this.minute+":"+this.second;
};
this.display=function(ele){
varclock=newClock();
ele.innerHTML=clock.toString();
window.setTimeout(function(){clock.display(ele);},1000);
};
}