首页 > 网站 > WEB开发 > 正文

JS显示时钟精确到毫秒

2024-04-27 15:11:12
字体:
来源:转载
供稿:网友

<script language="javascript">function countdown(endtime, today){	today = new Date();	target_time=new Date(endtime);	timeold=(target_time.getTime()-today.getTime()); 	sectimeold=timeold/1000;	secondsold=Math.floor(sectimeold); 	msPerDay=24*60*60*1000;	e_daysold=timeold/msPerDay;	daysold=Math.floor(e_daysold); 	e_hrsold=(e_daysold-daysold)*24; 	hrsold=Math.floor(e_hrsold); 	e_minsold=(e_hrsold-hrsold)*60; 	minsold=Math.floor(e_minsold); 	e_seconds=(e_minsold-minsold)*60;	seconds=Math.floor(e_seconds); 	e_millisecond=(e_seconds-seconds)*1000;	millisecond=Math.floor(e_millisecond);    millisecond10=Math.floor(millisecond/10);	/*	s = 'timeold: '+ timeold + '<br>';	s+= 'sectimeold:' + sectimeold + '<br>';	s+= 'secondsold:' + secondsold + '<br>';	s+= 'msPerDay:' + msPerDay + '<br>';	s+= 'e_daysold:' + e_daysold + '<br>';	s+= 'daysold:' + daysold + '<br>';	s+= 'e_hrsold:' + e_hrsold + '<br>';	s+= 'hrsold:' + hrsold + '<br>';	s+= 'e_minsold:' + e_minsold + '<br>';	s+= 'minsold:' + minsold + '<br>';	s+= 'e_seconds:' + e_seconds + '<br>';	s+= 'seconds:' + seconds + '<br>';	s+= 'e_millisecond:' + e_millisecond + '<br>';	s+= 'millisecond:' + millisecond + '<br>';	s+= 'millisecond10:' + millisecond10;		document.write(s);	*/	the_element = document.getElementById('counttime');	the_element.innerHTML="仅剩 "+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+millisecond10/*+"毫秒"*/ ;		//today.setSeconds(today.getSeconds() + 0.01);	window.setTimeout("countdown('" + endtime + "', today)", 100); } </script>
<table>  <tr>    <td width="175">    <SPAN id="counttime" style="FONT-WEIGHT: bold; COLOR: #000000; FONT-FAMILY:Arial"></SPAN>     <script language="Javascript">		var endtime = '1-1-2012 00:00:00';		var today = new Date();		countdown(endtime, today);    </script>   </td>  </tr></table>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表