日期比较的处理

111 阅读1分钟

有两个输入框,一个是开始时间,一个是结束时间,格式都是 xxxx-yy-zz

现在要确定输入的开始时间不能比结束时间要晚

处理方式是先把字符串中的 ‘-’去掉, 方法是str.replace(/-/g, ''), 再调用parseInt方法转换为number类型进行比较。

let start = parseInt(str.replace(/-/g, ''))

let end= parseInt(str1.replace(/-/g, ''))

start-end<0