getCurrentTime() {
//改时间数据格式
var currentTime= new Date();
const formattedDate =
`${currentTime.getFullYear()}-${this.padZero(currentTime.getMonth() + 1)}-${this.padZero(currentTime.getDate())} ${this.padZero(currentTime.getHours())}:${this.padZero(currentTime.getMinutes())}:${this.padZero(currentTime.getSeconds())}`;
return formattedDate;
},
//时间格式转换
padZero(num) {
return num < 10 ? `0${num}` : num;
},
// 打印当前年月日时分秒
console.log(this.getCurrentTime())
前端获取当前年月日时分秒
最新推荐文章于 2024-09-14 14:42:48 发布