js实现当前世界各国时区时间代码。主要有:北京时间,孟买时间,纽约时间,东京时间,巴黎时间,悉尼时间等。
使用方法
1、head引入css文件
<style> body { background-image: url("img/bj.jpg"); background-size: cover; background-repeat: no-repeat; } #container { position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 100%; height: 100%; line-height: 90px; text-align: center; background: rgba(255, 255, 255, 0.3); } #time_body { margin: auto; position: absolute; top: 0; bottom: 0; right: 0; left: 0; height: 50%; width: 90%; } .time { font-size: 90px; } .title { font-size: 40px; margin-bottom: 60px; } li { float: left; width: 30%; list-style: none; } </style>2、body引入HTML代码
<div id="container"> <div id="time_body"> <ul> <li id="beijing" class="time"></li> <li id="mengmai" class="time"></li> <li id="niuyue" class="time"></li> <li class="title">北京时间</li> <li class="title">孟买时间</li> <li class="title">纽约时间</li> <li id="dongjing" class="time"></li> <li id="bali" class="time"></li> <li id="xini" class="time"></li> <li class="title">东京时间</li> <li class="title">巴黎时间</li> <li class="title">悉尼时间</li> </ul> </div> </div> <script type="text/javascript"> function startTime() { document.getElementById('beijing').innerHTML = calcTime(+8) document.getElementById('mengmai').innerHTML = calcTime(+5.5) document.getElementById('niuyue').innerHTML = calcTime(-5) document.getElementById('dongjing').innerHTML = calcTime(+9) document.getElementById('bali').innerHTML = calcTime(+2) document.getElementById('xini').innerHTML = calcTime(+10) t = setTimeout('startTime()', 1000) } function checkTime(i) { if (i < 10) { i = "0" + i } return i } function calcTime(offset) { var d = new Date(); var utc = d.getTime() + (d.getTimezoneOffset() * 60000); var nd = new Date(utc + (3600000 * offset)); var h = nd.getHours() var m = nd.getMinutes() var s = nd.getSeconds() h = checkTime(h) m = checkTime(m) s = checkTime(s) return h + ":" + m + ":" + s } </script>3、body默认函数调用
onLoad="startTime()