本文实例为大家分享了javascript实现智能手环时间显示的具体代码,供大家参考,具体内容如下
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >Document</ title >
< style >
#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;
}
</ style >
</ head >
< body >
< div id = "shijian" >显示当前时间</ div >
< script >
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)
</script>
</ body >
</ html >
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/horizon12/article/details/108652609