日 期: {{nowData}}
说明:其中nowData是获取的数据值
具体代码如下:
data: { nowData: "", },
this.setData({ nowData: this.getNowDate(), })
getNowDate: function () { var date = new Date(); var year = date.getFullYear() //年 var month = date.getMonth() + 1//月 var day = date.getDate()//日 var hour = date.getHours()//时 var minute = date.getMinutes()//分 var second = date.getSeconds()//秒 var xiaoshi = ""; if (hour < 10) { xiaoshi = "0" + hour; } else { xiaoshi = hour + ""; } var fenzhong = ""; if (minute < 10) { fenzhong = "0" + minute; } else { fenzhong = minute + ""; } var miao = ""; if (second < 10) { miao = "0" + second; } else { miao = second + ""; } console.log(year + '-' + month + '-' + day + ' ' + xiaoshi + ':' + fenzhong + ':' + miao); this.setData({ nowTime: year + '-' + month + '-' + day + ' ' + xiaoshi + ':' + fenzhong + ':' + miao }) },