2016-09-28 3 views
0

なぜこのスクリプトは機能しませんか? コメントが指摘するようにそれは28/09/2016 0:01 PMの後リダイレクト先の日付と時刻

<script language="javascript"> 
// Redirect naar index-afgesloten.html 

var currentdate = new Date(); 

var datetime = "Last Sync: " + currentdate.getDate() + "/"+(currentdate.getMonth()+1) 
+ "/" + currentdate.getFullYear() + " @ " 
+ currentdate.getHours() + ":" 
+ currentdate.getMinutes(); 

if(new Date() > "28/09/2016 00:01PM") // Datum omschakeling 
{ 
location.href ="index-afgesloten.html"; // redirect url 
} 

</script> 

おかげ

+1

タグを変更してください。 JavaScriptの質問です。あなたはJavaとタグ付けしました – siarheib

答えて

0

をリダイレクトする必要があり、これはJavaScriptとJavaのではないです:)

今あなたが作成していますif文の中のDateオブジェクト。現在の時刻に日付を作成します。次に文字列と比較しようとしますが、これは不可能です。日付を比較する場合は、2つの日付オブジェクトを作成し、それらを比較するためにdataObject.getTime()メソッドを使用する必要があります。

Compare two dates with JavaScript

幸運:私はあなたを助ける必要があるリンクを見つけました!

0

はこれを試してみて、タグを変更:)

var currentdate = new Date(); 
var datetime = "Last Sync: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + 
    "/" + currentdate.getFullYear() + " @ " + 
    currentdate.getHours() + ":" + 
    currentdate.getMinutes(); 

var dateAfter = new Date('2016-09-28T00:00:00'); 

if (currentdate > dateAfter) // Datum omschakeling 
{ 
    location.href = "index-afgesloten.html"; 
}