简体   繁体   English

Javascript从日期开始获取星期几

[英]Javascript get day of week from date

I am creating a reservation application in one of my classes. 我正在其中一个课程中创​​建预订应用程序。 In the app, a user is trying to create a recurring reservation by giving a start date and end date and a day of the week they want the reservation. 在该应用程序中,用户试图通过提供开始日期和结束日期以及他们希望保留的星期几来创建重复的保留。 I want to return a list of dates that they have reservations on; 我想返回他们保留的日期列表; here's an example 这是一个例子

Start Date: 02/01/2015 End Date: 03/01/2015 Days of the Week: Monday and Wednesday. 开始日期:2015年2月1日结束日期:2015年3月1日星期几:星期一和星期三。

In this example, I want to return all the Mondays and Wednesdays during this time. 在此示例中,我想返回这段时间内的所有星期一和星期三。 I would like to do this in Javascript. 我想用Javascript做到这一点。

Loop through the dates using: 使用以下命令循环浏览日期:

tomorrow.setDate(today.getDate()+1);

And check if the day of the week is monday or wednesday using: 并使用以下命令检查星期几是星期一还是星期三:

tomorrow.getDay()

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

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