jquery时钟

<script type="text/javascript">

function getDate(){
var mydate = new Date(); //时间对象
var year=mydate.getFullYear(); //年
var month=mydate.getMonth()+1; //月
var date=mydate.getDate(); //日
var day=mydate.getDay(); //星期几
var hour=mydate.getHours(); //小时
if (hour<10) {
hour='0'+hour;
}
var minute=mydate.getMinutes(); //分钟
if (minute<10) {
minute='0'+minute;
}
var second=mydate.getSeconds(); //秒
if (second<10) {
second='0'+second;
}

//str = year+'-'+month+'-'+date+' '+hour+':'+minute+':'+second;
str = hour+':'+minute+':'+second;
tiobj = document.getElementById("ti");
tiobj.innerHTML=str;
}
getDate(); //先获取一次时间,然后再没秒刷新
setInterval(getDate,1000);


</script>

posted @ 2018-08-06 09:54  进击的巨人X  阅读(474)  评论(0编辑  收藏  举报