检查date是否在过去的Javascript
所有,我使用dateselect器的jQuery UI。 我试图用javascript来检查,但用户input的date是过去的。 这是我的表单代码:
<input type="text" id="datepicker" name="event_date" class="datepicker">
那么我怎样才能用Javascript来检查它,以确保它不是过去的date? 谢谢
var selectedDate = $('#datepicker').datepicker('getDate'); var now = new Date(); now.setHours(0,0,0,0); if (selectedDate < now) { // selected date is in the past }
var datep = $('#datepicker').val(); if(Date.parse(datep)-Date.parse(new Date())<0) { // do something }
function isPrevDate() { alert("startDate is " + Startdate); if(Startdate.length != 0 && Startdate !='') { var start_date = Startdate.split('-'); alert("Input date: "+ start_date); start_date=start_date[1]+"/"+start_date[2]+"/"+start_date[0]; alert("start date arrray format " + start_date); var a = new Date(start_date); //alert("The date is a" +a); var today = new Date(); var day = today.getDate(); var mon = today.getMonth()+1; var year = today.getFullYear(); today = (mon+"/"+day+"/"+year); //alert(today); var today = new Date(today); alert("Today: "+today.getTime()); alert("a : "+a.getTime()); if(today.getTime() > a.getTime() ) { alert("Please select Start date in range"); return false; } else { return true; } } }