HTML5代码
<div id="time">
<span id="hour"></span>
<span id="data"></span>
</div>
CSS代码
#time{
float: right;
width: auto;
padding:0 50px;
border-left: 2px solid rgba(255,255,255,.3);
height: 54px;
margin-top: 13px;
margin-left: 40px;
color:#fff;
cursor: default;
text-align: center;
}
#hour{
display: block;
width: auto;
font-size: 22px;
height: 34px;
line-height: 34px;
color:#fff;
cursor: default;
}
#data{
display: block;
width: auto;
font-size: 10px;
height:20px;
line-height: 20px;
color:#fff;
cursor: default;
}
jquery代码
/*时间计数器*/
function p(s) {
return s < 10 ? '0' + s: s;
}
function nowtime() {
var myDate = new Date();
var year = myDate.getFullYear(); //获取当前年
var month = myDate.getMonth()+1; //获取当前月
var date = myDate.getDate(); //获取当前日
var h = myDate.getHours(); //获取当前小时数(0-23)
var m = myDate.getMinutes(); //获取当前分钟数(0-59)
var s = myDate.getSeconds();
var data = year+ '-' + p(month)+ "-"+ p(date);
var hour = p(h)+ ':'+ p(m);
$("#data").html(data);
$("#hour").html(hour);
}
nowtime();
setInterval(nowtime,1000);