一、引入moment.js,在man.js中
import moment from 'moment'//导入文件
Vue.filter('formate', function (time, format) {
if(time){
return moment(time).format(format)
}
})
二、在项目中使用就 this.$moment
var startTime = this.$moment().format("YYYY-MM-DD HH:mm:ss")
var endTime = this.$moment().subtract(1, "days").format("YYYY-MM-DD HH:mm:ss")
1.获取当前时间
2.往前推1天,1就是要往前推的参数
本文介绍了如何在Vue项目中利用moment.js进行时间格式化。通过导入并注册自定义过滤器,实现了时间戳到指定格式时间字符串的转换。同时,演示了如何使用this.$moment获取当前时间和前一天的时间。

2271

被折叠的 条评论
为什么被折叠?



