var dt1 = new Date();
dt1.setDate(dt1.getDate()-1);
var dt2 = new Date();
if (dt2>dt1)
alert("good");
else
alert("something is really wrong");

解决方案 »

  1.   

    vbscript可以用datediff
      day=DateDiff("d",dt1,dt2)
    javascript好象只能用valueOf()相减了
      day=(dt2.valueOf( )-dt1.valueOf( ))/86400000
      

  2.   

    哥们,你的哪个valueof()不好使啊,你再看看我的问题,谢谢!!值A为读出数据库中日期类型的字段值 a = ors("Start_Time")  假设为(2001-9-3 17:12:21),
    值B为现在日期 var b = new Date();  值为 Wed Sep 5 10:55:11 UTC+0800 2001 如何将A,B比较,得出小时差? 
      

  3.   

     怎么还有数据库啊?用ASP的?
      

  4.   

    var astr = "2001-9-3 17:12:21";
    astr=astr.replace("-","/");
    var a = new Date(astr);
    var bstr = "Wed Sep 5 10:55:11 UTC+0800 2001";
    var b = new Date(bstr);
    hours = parseInt((b.getTime()-a.getTime())/3600000);