js判断传过来的时间距今几天

判断距今几天

time2(data){
 	 var date = data.toString();
   	 var year = date.substring(0,4);
	 var month = date.substring(5,7);
	 var day = date.substring(8,10);
	 var d1 = new Date(year+'/'+month+'/'+day);
	
	  var dd = new Date();
	  var y= dd.getFullYear();
	  var m=dd.getMonth()+1;
	  var d=dd.getDate();
	    
	  var d2 = new Date(y+'/'+m+'/'+d);
	  var iday = parseInt(d2-d1)/1000/60/60/24;
	  console.log(iday,'差几天')
	  this.chaTime.push(iday)
},

你可能感兴趣的:(常用方法,js)