微信小程序:将yyyy-mm-dd格式的日期转换成yyyy-mm-dd hh:mm:ss格式的日期

代码如下:

changeDate1(e) {
    console.log(e);
    var date =  new Date(e.detail.value); 
    console.log(date);
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
    const formatNumber = n => {
      n = n.toString()
      return n[1] ? n : '0' + n
    }
    var dateString = [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
    console.log(dateString);
    this.QueryParams.pestDate = dateString
        this.setData({
            'material.pestDate': e.detail.value
        });
  },