1.安装
npm install moment --save
2.在main.js引入
import * as moment from "moment"; //导入文件 moment.locale("zh-cn"); //需要汉化 Vue.prototype.moment = moment; //赋值使用
3.在页面直接使用
支持的度量有 years、months、weeks、days、hours、minutes 和 seconds。 this.moment().format(); // 2022-09-29T17:30:22+08:00 this.moment().format("YYYY-MM-DD") // 2022-09-29 this.moment().valueOf() // 当前时间转时间戳 this.moment().format('E'); //今天是这周第几天 this.moment().add(7-weekOfday, 'days').format('YYYY-MM-DD'); //周日日期 this.moment().subtract(weekOfday-1, 'days').format('YYYY-MM-DD'); //周一日期 this.moment().subtract(1, 'days').format("YYYY-MM-DD") // 昨天 this.moment().subtract(1, 'months').format("YYYY-MM-DD") // 一个月之前 this.moment().subtract(1, 'years').format("YYYY-MM-DD") // 一个年之前 this.moment().add(1, 'days').format("YYYY-MM-DD") // 明天 this.moment().add(1, 'months').format("YYYY-MM-DD") // 下个月之前 this.moment().add(1, 'years').format("YYYY-MM-DD") // 明年年之前 this.moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'); // 今日起始时间 this.moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'); // 今日结束时间
3121

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



