2011-09-14 18 views
0

JavaScriptチェック日付は今日または過去ではありません。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'; 
} 

私が入ってくる形式を変更することはできません

+2

質問してください。 –

+0

'Date.parse'を見てください。あなたはその分割をする必要はありません。 'var x = new Date(Date.parse(c))' – Hemlock

答えて

2

が見えます。ここでは、以下の場合に変更された状態である:

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())) { 
    ... 
} 
+0

私はIE7では正しく動作しないかもしれないということは、悪いことだと思いますか? –

1

更新このライン:あなたは99%がそれを持っているよう

// 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'; 
} 
0

はコンストラクタで文字列の代わりに月 の数を入れてみてください。 6月の代わりに6をつけてください。

関連する問題