加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vue 日期时间过滤器

发布时间:2020-12-16 23:14:46 所属栏目:百科 来源:网络整理
导读:来自:https://blog.csdn.net/m0_37068028/article/details/72898154 侵删 来自:https://segmentfault.com/a/1190000010378259 侵删 第一种: {{date | formatDate}} //date.jsexport function formatDate (date,fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.

来自:https://blog.csdn.net/m0_37068028/article/details/72898154 侵删

来自:https://segmentfault.com/a/1190000010378259 侵删

第一种:

{{date | formatDate}}

//date.jsexport function formatDate (date,fmt) {   if (/(y+)/.test(fmt)) {   fmt = fmt.replace(RegExp.$1,(date.getFullYear() + '').substr(4 - RegExp.$1.length)) } let o = {   'M+': date.getMonth() + 1,   'd+': date.getDate(),   'h+': date.getHours(),   'm+': date.getMinutes(),   's+': date.getSeconds() } for (let k in o) {     if (new RegExp(`(${k})`).test(fmt)) {     let str = o[k] + ''     fmt = fmt.replace(RegExp.$1,(RegExp.$1.length === 1) ? str : padLeftZero(str))   } }   return fmt}function padLeftZero (str) {   return ('00' + str).substr(str.length)}

第二种:

npm 
Vue.filter('moment',= formatString || 'YYYY-MM-DD HH:mm:ss' moment.unix(value).format(formatString); <span style="color: #008000">/<span style="color: #008000"> eslint-disable no-new <span style="color: #008000">/
<span style="color: #0000ff">new
<span style="color: #000000"> Vue({
el:
'#app'<span style="color: #000000">,template:
''<span style="color: #000000">,components: { App }
})

结果:

2017

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读