JS时钟--星期 年 月 日 时 分

 var clock = function(clockName){
var mydate = new Date();
var hours = mydate.getHours();
var minutes = mydate.getMinutes();
var seconds = mydate.getSeconds();
var month = (mydate.getMonth()+1);
var date = mydate.getDate();
var day = new Date().getDay();
var text = "";
switch (day) {
case 0:
text = "周日";
break;
case 1:
text = "周一";
break;
case 2:
text = "周二";
break;
case 3:
text = "周三";
break;
case 4:
text = "周四";
break;
case 5:
text = "周五";
break;
case 6:
text = "周六";
break;
}
if(month < 10){
month = '0' + month;
}
if(date < 10){
date = '0' + date;
}
if(hours < 10){
hours = '0' + hours;
}
if(minutes < 10){
minutes = '0' + minutes;
}
if(seconds < 10){
seconds = '0' + seconds;
}
var str = text +" "+ month + "-" + date + " " + hours +":"+ minutes;
$('#' + clockName).html("").text(str);
}

使用:

clock('clock');
    setInterval(function(){
        clock('clock');
    },1000);

上一篇:一个简易内存池(C++)


下一篇:【学习】linux环境下nginx文件彻底删除