获取未来几天的日期以及是星期几
/** * 获取时间 * day_count 是多少天 * */ function getDays(day_count) { var date = new Date(); var dates = []; var week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']; for (var i = 0; i <= day_count; i++) { var d = null; " " var date1 = date.getDate(); var month = date.getMonth()+1; if(month < 10){ month = "0" + month; } if(date1 < 10){ date1 = "0" + date1; } d = date.getFullYear() + "-" + month + "-" + date1; var weeks = ""; var day = new Date(d); var z = day.getDay(); weeks = week[z]; dates.push({ "date": d, "week": weeks }); date.setDate(date.getDate() + 1); } return dates; };
使用:
//获取未来一个月的日期,以及星期 var dataList = getDays(29);
今天整理一下代码