当前位置:网站首页>Timestamp to formatted date

Timestamp to formatted date

2022-04-23 17:47:00 Sanxiaochi 513

Define a global filter :

Vue.filter('dataFormat',function(originVal){
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2,'0')
  const d = (dt.getDate() + '').padStart(2,'0')
  const hh = (dt.getHours() + '').padStart(2,'0')
  const mm = (dt.getMinutes() + '').padStart(2,'0')
  const ss = (dt.getSeconds() + '').padStart(2,'0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

padStart See :padStart() Method ,padEnd() Method _ Mr. Waibo's blog -CSDN Blog _padstartpadStart() Method ,padEnd() Method ES2017 The function of string completion length is introduced . If a string is not long enough , Will be completed at the head or tail .padStart() For head completion ,padEnd() For tail completion .'x'.padStart(5, 'ab') // 'ababx''x'.padStart(4, 'ab') // 'abax''x'.padEnd(5, 'ab') // 'xabab''x'.padhttps://blog.csdn.net/ixygj197875/article/details/79090578

版权声明
本文为[Sanxiaochi 513]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230550325391.html