js实现时间走动效果

用jQuery获取网页元素赋值即可,已用红色高亮显示(此方法务必初始加载):

function showLeftTime()

{
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
if(month<10){
month='0'+month;
}
var day=now.getDate();
if(day<10){
day='0'+day;
}
var hours=now.getHours();
if(hours<10){
hours='0'+hours;
}
var minutes=now.getMinutes();
if(minutes<10){
minutes='0'+minutes;
}
var seconds=now.getSeconds();
if(seconds<10){
seconds='0'+seconds;
}
var showTime=year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
$('#nowTime').html(showTime);
//一秒刷新一次显示时间
var timeID=setTimeout(showLeftTime,1000);
}

你可能感兴趣的:(js)