剩余天数计算

let dateDiff =
					new Date(this.endTime).getTime() -
					new Date(this.startTime).getTime(); //时间差的毫秒数
				if (dateDiff <= 0) { 
					// "结束时间必须大于开始时间";
					// this.leaevDate = "";
					// this.dateEnd = "";
					return;
				}
				console.log(dateDiff)
				let dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
				let leave1 = dateDiff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
				let hours = Math.floor(leave1 / (3600 * 1000)); //计算出小时数
				let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
				let minutes = Math.floor(leave2 / (60 * 1000)); //计算相差分钟数
				this.leaevDate =
					dayDiff + "天" + hours + "小时" + minutes + "分钟";
				console.log(this.leaevDate)
    原文作者:WJLSH123
    原文地址: https://blog.csdn.net/WJLSH123/article/details/123279679
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞