需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html。
2、在index.html中的<script>标签,输入js代码:
var a = '2019-06-01 12:05:20';
var date = new Date(a.replace('-', '/'));
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类型后和当前系统时间对比的结果打印出来。