JS获取某个时间戳与当前时间之间的差距,并转化为 天,时,分

function calculateDiffTime(start_time) {
	if(!parseInt(start_time)) return "-";
		var endTime = Math.round(new Date() / 1000);
	
		var timeDiff = endTime - start_time
		var day = parseInt(timeDiff / 86400);
		var hour = parseInt((timeDiff % 86400) / 3600);
		var minute = parseInt((timeDiff % 3600) / 60);
	
		day = day?(day+'天'):'';
		hour = hour?(hour+"时"):'';
		minute = minute?(minute+"分"):'';
		return day + hour + minute + '之前';
}

你可能感兴趣的:(前路漫漫我会走下去!)