获取一个月前的时间到昨天的时间段

let data = {};
const today = new Date();
const yesterday = new Date();
const yestermon = new Date();
yesterday.setTime(today.getTime() - 1000 * 60 * 60 * 24);
yestermon.setTime(today.getTime() - 1000 * 60 * 60 * 24 * 31);
data.endTime = yesterday.getFullYear() + '-' + ((yesterday.getMonth() + 1) < 10 ? '0' + (yesterday.getMonth() + 1) : (yesterday.getMonth() + 1)) + '-' + (yesterday.getDate() < 10 ? '0' + yesterday.getDate() : yesterday.getDate());
data.startTime = yestermon.getFullYear() + '-' + ((yestermon.getMonth() + 1) < 10 ? '0' + (yestermon.getMonth() + 1) : (yestermon.getMonth() + 1)) + '-' + (yestermon.getDate() < 10 ? '0' + yestermon.getDate() : yestermon.getDate());

 

你可能感兴趣的:(jq)