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))+"天")  

解决方案 »

  1.   

    上面的上面的老兄在说javascriptString begin="2004-01-01";
    String end = "2004-09-09";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date beginDate = sdf.parse(begin);
    Date endDate = sdf.parse(end);利用SimpleDateFormat类可以把String转换成Date,即问题转换成判断时间是否在两个Date之间。
    两种方法:
    1用Date类的compareTo方法
    2把时间统一转换为long型判断(Date类有getTime方法)
      

  2.   

    public Date(int year,
                int month,
                int date,
                int hrs,
                int min)
    before
    public boolean before(Date when)
    Tests if this date is before the specified date. Parameters:
    when - a date. 
    Returns:
    true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by when; false otherwise.--------------------------------------------------------------------------------after
    public boolean after(Date when)
    Tests if this date is after the specified date. Parameters:
    when - a date. 
    Returns:
    true if and only if the instant represented by this Date object is strictly later than the instant represented by when; false otherwise.