uniapp使用moment.js格式化时间戳
首先导入moment.js并将语言转成中文。
import moment from "moment";
//设置语言为中文
moment.locale("zh-cn");
1.格式化成月份
this.monthes.MM = moment(this.monthes.stime).format("MM");
2.格式化成天数
this.monthes.DD = moment(this.monthes.stime).format("DD");
3.格式化距离现在多少天
//这里的atime单位是s,所以要乘以1000转化为ms
this.xxx.cnTime=moment(this.xxx.atime*1000).fromNow();