JS字符串类型转日期然后进行日期比较

 

1、字符串转日期格式

var stringToDate = function(dateStr,separator){ 
    if(!separator){ 
        separator="-"; 
    } 
    var dateArr = dateStr.split(separator); 
    var year = parseInt(dateArr[0]); 
    var month; 
    //处理月份为04这样的情况                          
    if(dateArr[1].indexOf("0") == 0){ 
        month = parseInt(dateArr[1].substring(1)); 
    }else{ 
         month = parseInt(dateArr[1]); 
    } 
    var day = parseInt(dateArr[2]); 
    var date = new Date(year,month -1,day); 
    return date; 
} 

日期比较

var dateFeedBack = stringToDate(gfeedbackDataStore.getRowSet().getRow(0).getItemValue("svfd_FEEBBACK_DATE"));
    var dateNow = stringToDate(callback_date);
    var days1 = parseInt(dateFeedBack.getTime()/(1000*60*60*24));
    var days2 = parseInt(dateNow.getTime()/(1000*60*60*24));
    if((days2-days1)>7){
      alert("提示:总部确认日期7天内才可退单!");
      return;
    }

 

posted @ 2017-04-26 11:28  Luca-  阅读(5628)  评论(0编辑  收藏  举报