代码如下:
点击查看代码
// 入参:time 格式是'2022-11-01 15:13:24’
function timeCompare(time) {
let end = new Date(time.replace(/-/g, '/'))
let endTime = end.getTime()
let nowTime = new Date().getTime()
return nowTime < endTime
}
// 入参:time 格式是‘20221101151324’
function timeCompare2(time) {
let timeInfo = formatEndTime(time)
let end = new Date(timeInfo.replace(/-/g, '/'))
let endTime = end.getTime()
let nowTime = new Date().getTime()
return nowTime < endTime
}
// 入参:value 格式是‘20221101151324’
function formatEndTime(value) {
return (
value.substring(0, 4) +
'-' +
parseInt(value.substring(4, 6)) +
'-' +
parseInt(value.substring(6, 8)) +
' ' +
value.substring(8, 10) +
':' +
value.substring(10, 12) +
':' +
value.substring(12, 14)
)
}