最近搜索

js 计算 2个日期。相差几天。

浏览:332
管理员 2022-10-21 02:07




	<script>
		function DateDiff(end){
	today = new Date();	
	end = new Date(end);
	if(end > today){
		days = parseInt(Math.abs(end - today) / 1000 / 60 / 60 / 24);
	}else{
		days = parseInt(Math.abs(end - today) / 1000 / 60 / 60 / 24); // 如果不限制对比时间和当前时间大小可以不用if
	}	
	return days;
}
	</script>
	
	
	//输出1
<script>document.write(DateDiff('2006-02-23'));</script>
//输出2
<script>document.write(DateDiff('2016-02-23'));</script>
//输出N
...



image.png




联系站长

站长微信:xiaomao0055

站长QQ:14496453