简体   繁体   English

显示上一周和下一周的日期

[英]Show Previous and next week dates

I have 2 buttons( Previous and next ) for week.我有 2 个按钮(上一个和下一个)用于一周。 In between the previous and next week button needs to show week ending date (Fridays) for that week.在上一周和下一周之间的按钮需要显示该周的周结束日期(星期五)。 I want to display previous week date from Sun 11/18 to Mon 11/26 when we click the previous week button.当我们单击上周按钮时,我想显示从 11 月 18 日星期日到 11 月 26 日星期一的上周日期。 Same as the next week button click event to show from Mon 11/26" to Sun 12/2. How it possible to show? and how to take the week ending date (Fridays) for that week?与下周按钮单击事件相同,从星期一 11/26" 到星期日 12/2 显示。如何显示?以及如何取该周的周结束日期(星期五)?

This's to get the date in 7 days, and from 7 days ago:这是为了在 7 天内获取日期,从 7 天前开始:

var today = new Date();
var nextWeek = Date.parse(new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7));
var previousWeek = Date.parse(new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7));

If you don't want a timestamp returned, remove the Date.parse() from it to receive a string like this:如果您不希望返回时间戳,请Date.parse()删除Date.parse()以接收如下字符串:

Mon Dec 03 2012 00:00:00 GMT+0100 (West-Europa (standaardtijd))

(This was returned on a system with Dutch language settings) (这是在具有荷兰语设置的系统上返回的)

To get the week dates, take a look at these 2 questions:要获取周日期,请查看以下 2 个问题:
JavaScript - get the first day of the week from current date JavaScript - 从当前日期获取一周的第一天
How to get first and last day of the week in JavaScript 如何在 JavaScript 中获取一周的第一天和最后一天

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM