输入js代码: var a = 2019-06-01 12:05:20; var date = new Date(a.replace(-, 2、在index.html中的script标签。
, /)); var now = new Date(); if (date.getTime() now.getTime()) { document.body.innerText = a + 大于当前系统时间; } else { document.body.innerText = a + 不大于当前系统时间; } 3、浏览器运行index.html页面,。
此时会将yyyy-MM-dd HH:mm:ss格式的字符串转换为Date类型后和当前系统时间对比的结果打印出来。