从JavaScript中的工作日获取下一个日期 [英] Get next date from weekday in JavaScript
问题描述
你会很善良,告诉我,如果这是可能的JavaScript返回给定的工作日的下一个日期(它可以是0-6或星期六 - 星期六的名字)。
would you be so kind and tell me if this is possible in JavaScript to return the next date of given weekday (it could be either a number 0-6 or names Sunday-Saturday).
例如,如果今天,2009年10月16日,我通过了:
Example, if today, on 16-Oct-2009 I passed in:
- 星期五,将返回今天的日期 2009年10月16日
- 星期六返回 2009年10月17日
- 星期四返回 2009年10月22日
- Friday, it would return today's date 16-Oct-2009
- Saturday returned 17-Oct-2009
- Thursday returned 22-Oct-2009
谢谢,
我真的希望得到一个答案,人们在线搜索这种功能将在这里结束,因为我没有发现在那里解决了这一切。这实际上不是租用编码器,因为解决方案可以免费 大家免费!我不认为你不需要评论,如果你不知道答案,但是,我感谢你的意见( @Andy& @Josh )。
Thanks, I really hope to get an answer and people, who search for this kind of function on-line would end up here, since I haven't found anything else out there that solves this. This, indeed ain't rent-a-coder, because the solution is accessible to everyone for free! I don't think you need to comment if you don't know the answer, I do, however, appreciate your comments (@Andy & @Josh).
推荐答案
只需添加7就不能解决问题。
Just adding 7 doesn't solve the problem.
以下功能会给你下一个
function nextDay(x){
var now = new Date();
now.setDate(now.getDate() + (x+(7-now.getDay())) % 7);
return now;
}
这篇关于从JavaScript中的工作日获取下一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!