1、字符串转日期格式
1 var stringToDate = function(dateStr,separator){ 2 if(!separator){ 3 separator="-"; 4 } 5 var dateArr = dateStr.split(separator); 6 var year = parseInt(dateArr[0]); 7 var month; 8 //处理月份为04这样的情况 9 if(dateArr[1].indexOf("0") == 0){ 10 month = parseInt(dateArr[1].substring(1)); 11 }else{ 12 month = parseInt(dateArr[1]); 13 } 14 var day = parseInt(dateArr[2]); 15 var date = new Date(year,month -1,day); 16 return date; 17 }
2. 日期比较
1 var dateFeedBack = stringToDate(gfeedbackDataStore.getRowSet().getRow(0).getItemValue("svfd_FEEBBACK_DATE")); 2 var dateNow = stringToDate(callback_date); 3 var days1 = parseInt(dateFeedBack.getTime()/(1000*60*60*24)); 4 var days2 = parseInt(dateNow.getTime()/(1000*60*60*24)); 5 if((days2-days1)>7){ 6 alert("提示:总部确认日期7天内才可退单!"); 7 return; 8 }