js 比较两个时间大小

比较两个日期时间点大小。格式:2023-01-31 14:05:452023-01-31 14:05
方法一:

const compareTime = (t1, t2) => {
	return ((new Date(t1.replace(/\-/g, "\/"))) > (new Date(t2.replace(/\-/g, "\/"))));
}

方法二:

const compareTime = (t1, t2) => {
	let time1 = new Date(Date.parse(t1))
	let time2 = new Date(Date.parse(t2))
	return time1 > time2
}

比较两个时间点大小。格式:14:05

const compareTime = (t1, t2) => {
	let d = new Date()
	let ft1 = d.setHours(t1.split(":")[0], t1.split(":")[1])
	let ft2 = d.setHours(t2.split(":")[0], t2.split(":")[1])
	return ft1 > ft2
}

你可能感兴趣的:(js,javascript)