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');//月末
相關文章
相關標籤/搜索