js判斷輸入日期時間是否在當前日期時間之前
阿新 • • 發佈:2019-02-03
//驗證輸入日期是否超過當前日期(日期時間) function checkTime() { var check = 0; var nowDate = new Date(); var date = nowDate.getFullYear()+"年"+(nowDate.getMonth()+1)+"月"+nowDate.getDate()+"日"; var input_time = $('#inspectTime').val(); var time_split2 = new Array(); time_split2 = input_time.split(" "); var time_split = new Array(); time_split = time_split2[0].split("-"); if(nowDate.getFullYear() < time_split[0]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("inspectTime").select(); } else if(nowDate.getFullYear()==time_split[0] ) { if(nowDate.getMonth()+1 < time_split[1]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("inspectTime").select(); } else if(nowDate.getMonth()+1 == time_split[1]) { if(nowDate.getDate() <= time_split[2]) { check = 0; alert('當前僅能錄入'+date+'之前的資料'); document.getElementById("inspectTime").select(); } else { check = 1; } } else { check = 1; } } else { check = 1; } return check; }