微信小程序获取近7天的时间

var timestamp = Date.parse(new Date());

timestamp = timestamp / 1000;

var date = new Date(timestamp * 1000);

//获取年份

var Y = date.getFullYear();

//获取月份

var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);

//获取当日日期

var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

 

//減7天的时间戳:

var before_timetamp = timestamp - 24 * 60 * 60 * 6;

//減7天的时间:

var n_to = before_timetamp * 1000;

var before_timetamp = new Date(n_to);

var Y_before = before_timetamp.getFullYear();

//月份

var M_before = (before_timetamp.getMonth() + 1 < 10 ? '0' + (before_timetamp.getMonth() + 1) : before_timetamp.getMonth() + 1);

//日期

var D_before = before_timetamp.getDate() < 10 ? '0' + before_timetamp.getDate() : before_timetamp.getDate();

你可能感兴趣的:(微信小程序获取近7天的时间)