moment.js 常用(几天前、相差几天、自然周、自然月)

let pickDate = moment(this.searchForm.date);
let firstDay = pickDate.day(0).format('YYYYMMDD');//上周天
let lastDay = pickDate.day(7).format('YYYYMMDD');//周天
let previousDate = moment(this.searchForm.date).subtract(1, "weeks").format("YYYY-MM-DD");//上周
let diff = pickDate.diff(moment(), 'days');//相差几天
 
 
var today = moment().format('YYYY-MM-DD');
var last7 = moment().subtract('days', 6).format('YYYY-MM-DD');//7天前
var lart30 = moment().subtract('days', 29).format('YYYY-MM-DD');//30天前
 
let week = moment(this.searchForm.week);
startTime = week.startOf('week').format('YYYYMMDD');//周初
endTime = week.endOf('week').format('YYYYMMDD');//周末
 
let month = moment();
startTime = month.startOf('month');//月初
endTime = month.endOf('month');//月末

转载于:https://www.cnblogs.com/zhaomeizi/p/9138976.html

你可能感兴趣的:(moment.js 常用(几天前、相差几天、自然周、自然月))