功能:
顯示當前日期
在對應頁面中的.js文件裏添加
注意:
日期格式化函數不要寫在Page({ ... })裏面
Page({
onLoad: function(options) {
// 日期
var today = new Date;
var solar = formatTime(today);
let show_day = new Array('日', '一', '二', '三', '四', '五', '六');
this.setData({
solarCalendor: solar.year + '年' + solar.month + '月' + solar.day + '日 · 星期' + show_day[today.getDay()]
})
},
})
// 日期格式化函數
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return {
year,
month,
day
}
}
效果顯示,可以去我的小程序看看效果哦,就在日曆中。
感覺有用的小夥伴,點個贊再走撒~