js获取当前时间年月日时间
时间: 2023-08-24 19:10:55 浏览: 22
您可以使用JavaScript的Date对象来获取当前时间的年月日时间。下面是一个示例代码:
```javascript
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // 月份从0开始,需要加1
var day = currentDate.getDate();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();
console.log("当前时间:" + year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds);
```
这段代码将会打印出当前时间的年月日时间,格式为"YYYY-MM-DD HH:MM:SS"。您也可以根据需要进行格式化输出。
相关推荐



