0

所以我只想找出日期是在今天之前还是将来的一天。所以基本上我有这个结构:

function data(startdate, enddate)
{
    var that = this;
    start = startdate;
    end = enddate;

    var today = new Date();
    today = today.getTime();
    today = Date.parse(today);

    this.status = false; // True = Server is in maintenance
    this.init = function()
    {
        isDone();
    }
    function isDone(){
        if( Date.parse(start) < today && today < Date.parse(end))
        {       
            that.status = true;
            console.log(that.status);
        }else
        {
            that.status = false;
            console.log(that.status);
        }
    }
}

比我这样称呼它:

var x1 = new Date(2013,2,23,12,3,45);
var x2 = new Date(2013,2,27,12,3,45);

var foobar = new data(x1,x2);
foobar.init();

所以试图弄清楚,javascript创造了什么:

start:1364036625000 
end: 1364382225000 
today: 1361796935000 

我还将它解析回标准格式:

start:Sat Mar 23 2013 12:03:45 GMT+0100 
end:Wed Mar 27 2013 12:03:45 GMT+0100 
today:Mon Feb 25 2013 13:54:56 GMT+0100

所以我不知道如何修复它或它如何工作......

4

1 回答 1

1

您的问题没有明确说明,但您似乎忘记(或忽略)月份在 javascript 中是零索引的。二月是1

于 2013-02-25T14:26:34.097 回答