开发者

JavaScript Check Date not today or in the past

JavaScri开发者_如何学Gopt Check Date not today or in the past.

var c = '10 JUN 2010'; // this is the format of the date coming in.
var temp = new Array();
temp = c.split(' ');

var x = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );

if (x.getTime() > getDate()) {
   alertstring = alertstring + '\n\nDEBUG CODE: 1 ' + x + '\n\n';
}

I cannot change the format coming in.


Looks like you 99% have it. Here it is with a modified if condition:

var c = '10 JUN 2010'; // this is the format of the date coming in.
var temp = new Array();
temp = c.split(' ');

var x = new Date ( temp[1]+" "+temp[0]+", "+temp[2] );

if (x.getTime() > (new Date().getTime())) {
    ...
}


Update this line:

// Get current date and time
var today = new Date();

// strip time to compare to the parse date
if (x.getTime() > new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime()) {
    // this date has not happened yet.
    alertstring = alertstring + '\n\nDEBUG CODE: 1 ' + x + '\n\n';
}


Try to put in constructor the number of month Instead of string . Instead of June put 6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜