欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用JavaScript获取现在的时间,并与特定时间进行比较

最编程 2024-08-08 17:44:06
...
// 获取当前时间 var currentDate = new Date(); // 定义指定时间 var specifiedDate = new Date("2021-01-01"); // 比较两个时间 if (currentDate > specifiedDate) { console.log("当前时间晚于指定时间"); } else if (currentDate < specifiedDate) { console.log("当前时间早于指定时间"); } else { console.log("当前时间等于指定时间"); }

推荐阅读