(编辑:jimmy 日期: 2024/12/24 浏览:2)
本文实例为大家分享了javascript实现智能手环时间显示的具体代码,供大家参考,具体内容如下
代码:
<!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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。