如何提醒下周的开始和结束日期
var weekCount = 0;
$(".week-next").live('click',function(){
var weekdate = new Date();
var fromweek = weekdate.setTime(weekdate.getTime() - 7 * 24 * 60 * 60 * 1000);
var toweek = weekdate.setTime(weekdate.getTime() - (weekdate.getDay() ? weekdate.getDay() : 7) + weekCount * 24 * 60 * 60 * 1000);
var prevweekstart = new Date(fromweek);
var prevweekends = new Date(toweek);
prevweekstart = prevweekstart.toLocaleString(),
prevweekends = prevweekends.toLocaleString(),
between = [];
alert(prevweekends);
});
答案 0 :(得分:0)
如果您的weekCount正在增加,则将其默认设置为1。您需要将当前时间加上下周时间存储在此处命名的变量(curr)中并相应地使用它。
这里+ 6用于获取星期五的日期
var weekcount = 1;
$(".week-next").live('click',function(){
var weekdate = new Date();
var curr = new Date(weekdate.getTime() + ( ( 7 * weekcount) * 24 * 60 * 60 * 1000) );
var fromweek = weekdate.setTime(weekdate.getTime() + (( 7 * weekcount) * 24 * 60 * 60 * 1000) );
var toweek = weekdate.setTime( (curr.getDate() - curr.getDay() ) + 6);
toweek = curr.setDate(toweek);
var prevweekstart = new Date(fromweek);
var prevweekends = new Date(toweek);
console.log(prevweekstart);
console.log(prevweekends);
});