JavaScript检查日期不是今天或过去。
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';
}
我无法更改格式。
答案 0 :(得分:3)
看起来你99%拥有它。这是一个修改过的if条件:
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())) {
...
}
答案 1 :(得分:2)
更新此行:
// 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';
}
答案 2 :(得分:0)
尝试将构造函数放入月份数 而不是字符串。 而不是六月放6。