cnpm install moment --save
main.js
import moment from 'moment'
Vue.prototype.moment = moment;
YYYY-MM-DD HH:mm:ss大写HH24小时 小写hh12小时
Vue.filter('formatDate', (input, formatString = "YYYY-MM-DD HH:mm:ss") => {
判断如果没有返回-
if(!input){
return '-'
}
//es5函数参数设置默认值
//const lastFormatString = formatString || ''
// moment(input) 把时间字符串转成时间对象
// format(formatString) 把时间对象,按照指定格式,格式化成符合条件的字符串
return moment(input).format(formatString)
})
方法中用 this.moment(datalist[i].endDate).format("YYYY-MM-DD HH:mm:ss")
vue 时间戳转换时间
最新推荐文章于 2022-08-16 23:26:31 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)