moment获取当前时间
时间: 2023-09-22 20:12:14 浏览: 90
获取当前时间
你可以使用JavaScript的内置对象Date来获取当前时间。具体代码如下所示:
```
let now = new Date();
let year = now.getFullYear();
let month = ("0" + (now.getMonth() + 1)).slice(-2);
let day = ("0" + now.getDate()).slice(-2);
let hour = ("0" + now.getHours()).slice(-2);
let minute = ("0" + now.getMinutes()).slice(-2);
let second = ("0" + now.getSeconds()).slice(-2);
let currentTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
console.log(currentTime);
```
这段代码会将当前时间格式化为"YYYY-MM-DD HH:mm:ss"的形式并输出到控制台上。
阅读全文