1、js时间倒计时
<script language="javascript"> /** * 倒计时 * www.jb200.com */ function JSTime(dateTime) { var aDate, oDate1, oDate2, iDays; var Digital=new Date(); var month = Digital.getMonth()+1; var year = Digital.getYear(); var day= Digital.getDate(); var hour=Digital.getHours(); var minute=Digital.getMinutes(); var sec.getSeconds(); oDate1 = new Date(month + '-' + day + '-' + year+' '+hour+':'+minute+':'+second); //转换为12-18-2006格式 // oDate2 = new Date(12 + '-' + 03+ '-' + 2008+' '+15+':'+00+':'+00); oDate2 = new Date(dateTime); if(oDate1<=oDate2){ var remainDay,remainHour,remainMinute,remainSecond; iDays = parseInt(Math.abs(oDate1 - oDate2));//把相差的毫秒数转换为天数 remainDay=iDays / 1000 / 60 / 60 /24; remainDay = Math.floor(iDays/1000/3600/24); iDays = iDays - (remainDay*1000*3600*24); remainHour = Math.floor(iDays/1000/3600); iDays = iDays - (remainHour*1000*3600); remainMinute = Math.floor(iDays/1000/60); iDays = iDays - (remainMinute*1000*60); remainSecond = Math.floor(iDays/1000); iDays = remainDay+"天"+remainHour+"小时"+remainMinute+"分"+remainSecond+"秒"; document.getElementById('time1').innerHTML=iDays; }else{ document.getElementById('time1').innerHTML='活动时间已开始,您有一天的体验时间,赶快体验吧!'; } } window.setInterval("JSTime('12-03-2008 10:00:00')",1000); </script>
附:距离某个时间还有多少天
<script language="javascript"> /** * 距离某个时间的天数 * www.jb200.com */ function datediff(today){ //sDate1和sDate2是yyyy-mm-dd格式 var aDate, oDate1, oDate2, iDays; var Digital=new Date(); var month = Digital.getMonth()+1; var year = Digital.getYear(); var day= Digital.getDate(); oDate1 = new Date(month + '-' + day + '-' + year); //转换为12-18-2006格式 oDate2 = new Date(month + '-' + today + '-' + year); if(oDate1<oDate2){ iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数 document.getElementById('dateti').innerHTML=iDays; }else{ oDate2 = new Date((month+1) + '-' + today + '-' + year); iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24); document.getElementById('dateti').innerHTML=iDays; } return iDays; } </script>