具体代码如下:
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})},