获取下个星期一的日期 [英] Getting the date of next Monday
本文介绍了获取下个星期一的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得下一个星期一的JavaScript?我在互联网上找不到任何东西,我也尝试了很多代码和理解,但我不能真正做到这一点。
How can I get the next Monday in JavaScript? I can't find anything of this in the internet and I have also tried a lot of codes and understanding of this but I can't really do it.
这是我的代码:
var d = new Date();
var day = d.getDay();
d = new Date(d.setDate(d.getDate() + day + (day == 0 ? -6 : 2)));
推荐答案
这样做:
var d = new Date();
d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
console.log(d);
这篇关于获取下个星期一的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文