var validUntil = document.noticeInfoForm.elements["obj.validUntil"].value;
var str =   validUntil.split("-");
alert(new Date() - new Date(str[0], str[1]-1, str[2])>0);
当我的validUntil=当前日期时,alert的结果还是TRUE。这个问题怎么解决啊!~

解决方案 »

  1.   


    //给日期对象添加一个比较大小的函数,参数other是另外一个要比较的日期,当这个日期比另外一个日期大时返回1,比另外一个日期小时返回-1,两个日期相等时返回0
    Date.prototype.CompareOther = function(other) {
            return this.getYear() > other.getYear() ? 1 : 
                            (this.getYear() < other.getYear() ? -1 :
                            (this.getMonth() > other.getMonth() ? 1 :
                            (this.getMonth() < other.getMonth() ? -1 :
                            (this.getDate() > other.getDate() ? 1 :
                            (this.getDate() < other.getDate() ? -1 : 0)))));
        }
        
        window.onload = function() {
            var d = new Date(2011, 10, 10);
            var i = "2010-11-10";
            var str = i.split("-");
            alert(new Date(str[0], str[1] - 1, str[2]).CompareOther(d));
        }
      

  2.   

    最后这一个比较的地方 new Date() 获取当前时间 包括时,分,秒 而new Date(y,m,d)这种格式 得到的时间日期是当天 但时,分,秒是00:00:00 所以 这个值只有在当天的00:00:00时才有可能是false