我使用此功能获取当前周
Date.prototype.getWeek = function(start)
{
start = start || 0;
today = new Date(this.setHours(0, 0, 0, 0));
var day = today.getDay() - start;
date = today.getDate() - day;
var giorni = [];
for (var i = 0;i<7;i++) {
giorni.push(new Date(today.setDate(date+i)));
}
return giorni;
}
var Dates = new Date().getWeek();
for(var i=0;i<7;i++){
$scope.setts.push({
"name":days[Dates[i].getDay()],
"short": days[Dates[i].getDay()].substring(0,3),
"data":Dates[i].toLocaleDateString().substring(0,5)
});
}
并且本周工作正常,但是有下一个和prev方法的问题显示错误的日期。
$scope.prev = function () {
var prev = new Date(today.setDate(date-7));
var dates = prev.getWeek();
$scope.setts = [];
for(var i=0;i<7;i++) {
$scope.setts.push({
"name":days[dates[i].getDay()],
"short": days[dates[i].getDay()].substring(0,3),
"data":dates[i].toLocaleDateString().substring(0,5)
});
}
}
有什么建议吗?
周末愉快!