<script type="text/javascript">
function btnCount_Click(){
var myDate = new Date();
this.myHour = myDate.getHours();
this.myMinute = myDate.getMinutes();
if(myMinute<10){
myMinute="0"+myMinute;
}
this.mySeconds = myDate.getSeconds();
if(mySeconds<10){
mySeconds="0"+mySeconds;
}
this.myWeek = myDate.getDay();
this.myYear = myDate.getFullYear() +'-';
this.myMonth = myDate.getMonth()+1+'-';
this.myDatee = myDate.getDate();
var time=myYear+myMonth+myDatee+" "+myHour+":"+myMinute+":"+mySeconds;
s1 = "2010-12-27" ;
s2 = myYear+myMonth+myDatee ;
document.getElementById('span_time').value=time+" | "+DateDiff(s1,s2)+"天";
setTimeout('btnCount_Click()',1000);
//alert("第一个日期;"+s1+"\n第二个日期:"+s2+"\n相差"+DateDiff(s1,s2)+"天") ;
}
//计算天数差的函数,通用
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2006-12-18格式
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2006格式
aDate = sDate2.split("-")
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
return iDays
}
</script>
<input id="span_time" type="text" style="width:200px"/>
<script>
btnCount_Click();
</script>
JS计算时间天数
最新推荐文章于 2023-11-19 23:02:11 发布