<script language="JavaScript">
<!--
var d1=new Date("2002","01"-1,"20");
var d2 = new Date("2002","10"-1,"11");
alert(d1.toLocaleString());
alert(d2.toLocaleString());
alert((d2-d1)/(24*3600000));
//-->
</script>
<!--
var d1=new Date("2002","01"-1,"20");
var d2 = new Date("2002","10"-1,"11");
alert(d1.toLocaleString());
alert(d2.toLocaleString());
alert((d2-d1)/(24*3600000));
//-->
</script>
var str1 = "2002-01-20";
var str2 = "2002-10-11";
execScript('n = DateDiff("d", str1, str2)','vbscript');
alert("两日期间相隔 "+ n +" 天");
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head><body>
<button onClick="btnCount_Click()">计算相差天数</button>
<script language="JavaScript"> function btnCount_Click(){
s1 = "2002-1-10"
s2 = "2002-10-1"
alert(DateDiff(s1,s2))
} //计算天数差的函数,通用
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
var aDate, oDate1, oDate2, iDays
aDate = sDate1.split("-")
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式
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>
</body>
</html>