本文实例为大家分享了javascript实现智能手环时间显示的具体代码,供大家参考,具体内容如下
代码:
Document#shijian{
width: 500px;height: 120px;background-color:#117dbb;
margin: 50px auto;line-height: 120px;
color: white;font-size: 22px;
text-align: center;
border-radius: 60px;
box-shadow:#4f535a 0px 5px 10px;
}
function showtime(){
var a = new Date()
var year = a.getFullYear()
var month =jiaLing(a.getMonth()+1)
var day =jiaLing(a.getDate())
var week = weekUp(a.getDay())
var houer =jiaLing(a.getHours())
var minute =jiaLing(a.getMinutes())
var second =jiaLing(a.getSeconds())
var str=year+"年"+month+"月"+day+"日 星期"+week+" " +houer+"时"+minute+"分"+second+"秒"
return str;
}
function weekUp(i){
var arr = ["日","一","二","三","四","五","六"]
return arr[i]
}
function jiaLing(i){
if(i<10){
return "0"+i;
}else{
return i;
}
}
setInterval(function(){
var oDiv= document.getElementById("shijian");
oDiv.innerHTML = showtime()
},1000)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。