日期:2014-05-16  浏览次数:20525 次

js中的时间显示

<script type="text/javascript">

//取得系统服务器时间

var date = $("#date").text();

var time = $.trim(date);

var ss = time.substring(6,8);

var mm = time.substring(3,5);

var hh = time.substring(0,2);

//设置js刷新时间,注意进制问题

var s = parseInt(ss,10);

var m = parseInt(mm,10);

var h = parseInt(hh,10);

var t;

function timedCount()

{

//显示时候是一位数字时候前面加0

var ks;

var km;

var kh;

if(s<10){

ks = "0"+s;

}else{

ks = s;

}

if(m<10){

km = "0"+m;

}else{

km = m;

}

if(h<10){

kh = "0"+h;

}else{

kh = h;

}

//显示时间

?

document.getElementById('showtime').value = kh+":"+km+":"+ks;

//随着时间增加 动态改变 时 分?

s = s+1;

if(s > 0 && (s%60)==0){

m += 1;

s = 0;

}

if(m > 0 && (m%60)==0){

h += 1;

m = 0;

}?

if(h == 24){

h = 0;

} ?

t = setTimeout("timedCount()",1000);

}

timedCount();

?

</script>