Fork me on GitHub

验证“开始日期大于结束日期”

具体代码如下:

 /**
   * 用时间戳来验证时间(开始和结束时间)(不含有时分秒)
   * @param startTime,endTime
   */
  function isValidTime(startTime,endTime){
    
     var startstrs = startTime.split("-");
     var startyear = startstrs[0];
     var startmonth = startstrs[1];
     var startday = startstrs[2];
     var startDate = new Date(startyear,startmonth,startday); 
     var starttime = startDate.getTime()/1000;
     
     var endstrs = endTime.split("-");
     var endyear = endstrs[0];
     var endmonth = endstrs[1];
     var endday = endstrs[2];
     var endDate = new Date(endyear,endmonth,endday); 
     var endtime = endDate.getTime()/1000;
     
     if(starttime>endtime){
         return false;
     }else{
         return true;
     }
    
  }

 

 

具体演示

 

 

posted on 2014-03-11 18:44  雨为我停  阅读(610)  评论(0编辑  收藏  举报