当前位置 : 主页 > 网络编程 > JavaScript >

获取从今天汪后倒退几天的时间数组

来源:互联网 收集:自由互联 发布时间:2021-06-28
countDays /** * @param {number} days - 要倒退的天数 * @returns {array} */function countDays (days) {if(days == '' || days == null || days == undefined || typeof days != "number"){return false;}var res = [];//返回数据var today = ne
countDays
/**
 * @param {number} days - 要倒退的天数
 * @returns {array}
 */
function countDays (days) {
	if(days == '' || days == null || days == undefined || typeof days != "number"){
		return false;
	}
	var res = [];//返回数据
	var today = new Date().getTime();//今天
	for(var i = 0; i < days; i++){
		var _day = new Date(today - 86400000 * i),
			year = _day.getFullYear(),
			month = (_day.getMonth() + 1),
			day = _day.getDate();
		month = month < 10 ? '0' + month : month;
		day = day < 10 ? '0' + day : day;
		res.push( year + '-' + month + '-' + day);
	}
	return res;
}
上一篇:rem.js
下一篇:vue-demo
网友评论