2013-06-28 91 views
-1

我正在爲培訓管理系統創建應用程序。我必須檢查當前的日期和時間是否大於數據庫中的日期和時間。如果是這樣,隱藏一些按鈕。但我的代碼不起作用。檢查當前日期時間是否大於或等於數據庫中的日期和時間

我不知道我做錯了什麼。我現在堅持了幾個小時。分貝中的日期格式爲dd-mm-yyyy,時間爲H:i。以下是我已經試過:

end_Time = data.end_Time; // to get the time from db 
    var CurrentDate = new Date(); 
    var arrDate = end_Time[0].end_date.split("-"); 
    var dbDate = new Date(arrDate[2], arrDate[1] - 1, arrDate[0]); 
    var hours = CurrentDate.getHours(); 
    var minutes = ("0" + (CurrentDate.getMinutes())).slice(-2); 
    var Current_Time = hours + ":" + minutes; 

    if (dbDate < CurrentDate) { 
     if ((end_Time[0].end_time) < Current_Time) { 
      $("#updateTrainingButton").hide(); 
      $("#sendInvitationButton").hide(); 
      $("#cancelTrainingButton").hide(); 
     } 
    } 
+1

什麼是不工作?怎麼了?你有任何錯誤信息? –

+0

我沒有收到任何錯誤消息..但按鈕不隱藏..我想我得到的時間和日期做錯了什麼,但不知道什麼..! –

+0

_檢查您正在創建的日期值。 – CBroe

回答

1

//我想應該是這樣的:

if (dbDate < CurrentDate) { 
    $("#updateTrainingButton").hide(); 
    $("#sendInvitationButton").hide(); 
    $("#cancelTrainingButton").hide(); 
}else if(dbDate == CurrentDate){ 
    if ((end_Time[0].end_time) < Current_Time) { 
     $("#updateTrainingButton").hide(); 
     $("#sendInvitationButton").hide(); 
     $("#cancelTrainingButton").hide(); 
    } 
} 
+0

Thnkx對於那..現在我發現我做錯了.. !!!! –

相關問題