<SCRIPT LANGUAGE="JavaScript">
<!--
//说明:这里用了Math.ceil()函数,向上取整,即零头算一天,^_^
var strDate1 = "2003-06-17 03:03:40.0";
var strDate2 = "2004-09-18 12:03:12.0";
strDate1=strDate1.substring(0,strDate1.lastIndexOf(".")).replace(/-/g,"/");
strDate2=strDate2.substring(0,strDate2.lastIndexOf(".")).replace(/-/g,"/");
var date1 = Date.parse(strDate1);
var date2 = Date.parse(strDate2);
alert("strDate2与strDate1相差"+Math.ceil((date2-date1)/(24*60*60*1000))+"天")
//-->
</SCRIPT>

解决方案 »

  1.   

    <script>
         d1 = new Date(2004,1,1,12,30,30);
         d2 = new Date(2004,1,2,12,30,30)
         s1 = d1.toLocaleString();
         s2 = d2.toLocaleString();
         a = (d2.getTime()-d1.getTime())/(24*60*1000);
         alert(a);
    </script>
      

  2.   

    <script>
         d1 = new Date(2004,1,1,12,30,30);
         d2 = new Date(2004,1,2,12,30,30);
         a = (d2.getTime()-d1.getTime())/(24*60*1000);
         alert(a);
    </script>
      

  3.   

    楼上的除错了
    a = (d2.getTime()-d1.getTime())/60*60*1000);
    我在页面中试了可以使用 结果是24
      

  4.   


    Math.ceil()不行啊
    比如:取2004-09-17 03:03:00.0和2004-09-18 05:03:00.0之间相隔几个小时
      

  5.   

    搞定
    <SCRIPT LANGUAGE="JavaScript">
    <!--var strDate1 = "2004-09-17 03:03:00.0";
    var strDate2 = "2004-09-17 04:05:00.0";
    strDate1=strDate1.substring(0,strDate1.lastIndexOf(".")).replace(/-/g,"/");
    strDate2=strDate2.substring(0,strDate2.lastIndexOf(".")).replace(/-/g,"/");
    var date1 = Date.parse(strDate1);
    var date2 = Date.parse(strDate2);
    alert("strDate2与strDate1相差"+(date2-date1)/(60*60*1000)+"小时")
    //-->
    </SCRIPT>