微信小程序:將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
        });
  },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM