const app = getApp()
Page({
data: {
date: new Date()
},
onLoad: function () {
// this.setData({ date: new Date() })
console.log(this.data.date.getFullYear()); // 报错 this.data.date.getFullYear is not a function
// setData赋值就没这个问题
this.setData({ date: new Date() });
console.log(this.data.date.getFullYear()); // 2020
},
})
date:new Date().getTime() 试一下应该可以
const formatDate = (date) => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return [year, month, day].map(formatNumber).join('/');
}
todayTime: util.formatDate(new Date()),