效果:
<div id='box' style="text-align: center;"></div>
<script>
//定时器实现试试更新
setInterval(function(){
var date = new Date();
getDat(date);
},10)
function getDat(date){
var month = date.getMonth()
month += 1
function zeroDeal(n){
if(n>=0 && n<=9){
n = '0' + n
}
return n;
}
//星期几,方法1
var zhou = date.getDay()
switch(zhou){
case 0 : zhou = '天';break;
case 1 : zhou = '一';break;
case 2 : zhou = '二';break;
case 3 : zhou = '三';break;
case 4 : zhou = '四';break;
case 5 : zhou = '五';break;
case 6 : zhou = '六';break;
}
//方法2
// var arr = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六']
// var day = get.getDay();
// day = arr[day];
return box.innerHTML = date.getFullYear()+'-'+zeroDeal(month) +'-'+zeroDeal(date.getDate())+' '+zeroDeal(date.getHours())+':'+zeroDeal(date.getMinutes())+':'+zeroDeal(date.getSeconds())+' '+'星期'+zhou
}
</script>
可拷贝区:
<div id='box' style="text-align: center;"></div>
<script>
//定时器实现试试更新
setInterval(function(){
var date = new Date();
getDat(date);
},10)
function getDat(date){
var month = date.getMonth()
month += 1
function zeroDeal(n){
if(n>=0 && n<=9){
n = '0' + n
}
return n;
}
//星期几,方法1
var zhou = date.getDay()
switch(zhou){
case 0 : zhou = '天';break;
case 1 : zhou = '一';break;
case 2 : zhou = '二';break;
case 3 : zhou = '三';break;
case 4 : zhou = '四';break;
case 5 : zhou = '五';break;
case 6 : zhou = '六';break;
}
//方法2
// var arr = ['星期天','星期一','星期二','星期三','星期四','星期五','星期六']
// var day = get.getDay();
// day = arr[day];
return box.innerHTML = date.getFullYear()+'-'+zeroDeal(month) +'-'+zeroDeal(date.getDate())+' '+zeroDeal(date.getHours())+':'+zeroDeal(date.getMinutes())+':'+zeroDeal(date.getSeconds())+' '+'星期'+zhou
}
</script>