JavaScript 对时间格式的检查与求时间差

$('img-collect').addEvent('click',function(e){
		var quantity = $('txt-quantity').value;
		var url = 'wishListShow.htm?action=addToWishList&productId=${param.id}&quantity='+quantity;
		opener.location.href=url;
		window.close();
	});

 

 

function importData(){
          var p = window.opener.document.theForm;
          p.TurkeyImpBtn.click();
          p.focus();
          window.close();
      }

 

 

function getDateDiff(date1,date2){
       var   re   =   /^(\d{4})\S(\d{1,2})\S(\d{1,2})\s(\d{1,2})\S(\d{1,2})$/;   
       var   dt1,dt2;   
       if   (re.test(date1))          {   
         dt1 =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3,RegExp.$4,RegExp.$5); 
       }else{
         alert("请正确输入时间格式!")
         return;
       }  
       if   (re.test(date2))   {   
         dt2   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3,RegExp.$4,RegExp.$5);   
       }else{
         dt2 = date2;
       } 
      return (dt2-dt1)/(1000 * 60 * 60 * 24)  
  }

 

把String 类型的时间转换成Timestamp类型的

SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy HH:mm:ss");


repairItemModel.setWarrdate(warrdate!=null&&warrdate!=""?new Timestamp(sdf.parse(warrdate).getTime()):DateUtils.getCurTimeStamp());

 

你可能感兴趣的:(JavaScript)