+
80
-

微信小程序wxs中无法使用new Date () 怎么办?

微信小程序wxs中无法使用new Date () 怎么办?


网友回复

+
0
-

wxs 中不能直接调用 javascript 中的Date函数,可以使用getDate来替代,代码如下:

	var tools= {
	  getDateTime: function (value) {
	    //不能使用 new Date()
	      var time = getDate(value);
	      var year = time.getFullYear();
	      var month = time.getMonth() + 1;
	      var date = time.getDate();
	      var hour = time.getHours();
	      var minute = time.getMinutes();
	      var second = time.getSeconds();
	      month = month < 10 ? "0" + month : month;
	      date = date < 10 ? "0" + date : date;
	      hour = hour < 10 ? "0" + hour : hour;
	      minute = minute < 10 ? "0" + minute : minute;
	      second = second < 10 ? "0" + second : second;
	      return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
	  }
	}

	module.exports = {
	  getDateTime: tools.getDateTime
	}

我知道答案,我要回答