话不多说,上代码
<!DOCTYPE html>
<html>
<head>
<title>js日期相减函数</title>
<script type="text/javascript">
window.onload=function(){
console.log(DateMinus('2018-8-8'));
}
//计算日期与当前日期相减得到天数
function DateMinus(sDate){
var sdate = new Date(sDate.replace(/-/g, "/"));
var now = new Date();
var days = now.getTime() - sdate.getTime();
var day = parseInt(days / (1000 * 60 * 60 * 24));
return day;
}
</script>
</head>
<body>
</body>
</html>