js格式化 Thu Mar 07 2019 12:00:00 GMT+0800 (中國標准時間) 及相互轉化


1 Thu Mar 07 2019 12:00:00 GMT+0800 (中國標准時間) 轉換為 2019-03-07 12:00:00
代碼如下

const d = new Date(Thu Mar 07 2019 12:00:00 GMT+0800 (中國標准時間))
  const resDate = d.getFullYear() + '-' + this.p((d.getMonth() + 1)) + '-' + this.p(d.getDate())
  const resTime = this.p(d.getHours()) + ':' + this.p(d.getMinutes()) + ':' + this.p(d.getSeconds())

 

p為不夠10添加0的函數

p(s) {
      return s < 10 ? '0' + s : s
},

2 2019-03-07 12:00:00轉換為 Thu Mar 07 2019 12:00:00 GMT+0800 (中國標准時間)
代碼如下

parserDate(date) {
      var t = Date.parse(date)
      if (!isNaN(t)) {
        return new Date(Date.parse(date.replace(/-/g, '/')))
      }
    },

 


免責聲明!

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



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