vue 日期时间过滤器
来自: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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |