getnowTime() { //获取当前时间
let now = new Date();
let _month = (10 > (now.getMonth() + 1)) ? '0' + (now.getMonth() + 1) : now.getMonth() + 1;
let _day = (10 > now.getDate()) ? '0' + now.getDate() : now.getDate();
let _hour = (10 > now.getHours()) ? '0' + now.getHours() : now.getHours();
let _minute = (10 > now.getMinutes()) ? '0' + now.getMinutes() : now.getMinutes();
let _second = (10 > now.getSeconds()) ? '0' + now.getSeconds() : now.getSeconds();
var time = now.getFullYear() + '-' + _month + '-' + _day + ' ' + _hour + ':' + _minute + ':' + _second;
console.log(time)
this.time = time
}
我是在onLoad中写的这个方法
在data中声明 time 就可以使用了 时间格式 2022-02-28 10:48:00