javascript - 如何在 jQuery 中仅打印两个特定日期之间的工作日日期?

标签 javascript jquery

在这里,我尝试在 jQuery 中打印特定日期的日期和完整工作日的数量,但它给我的输出显示如下:-

输出

[Fri Jun 01 2018 00:00:00 GMT+0530 (IST),
 Sat Jun 02 2018 00:00:00 GMT+0530 (IST),
 ......,
 ......, //further till end date
]

我使用的代码是:-

 var start = $("#txtFromDate").datepicker("getDate"),
  end = $("#txtToDate").datepicker("getDate"),
  currentDate = new Date(start.getTime()),
  between = []
;

while (currentDate <= end) {
    between.push(new Date(currentDate));
    currentDate.setDate(currentDate.getDate() + 1);
}
    console.log(between);

编辑代码:-

var start = $("#txtFromDate").val($.datepicker.formatDate('M dd yyyy', new Date())),
end = $("#txtToDate").val($.datepicker.formatDate('M dd yyyy', new Date())),
currentDate = new Date(start.getTime()),
between = []
;

while (currentDate <= end) {
    between.push(new Date(currentDate));
    currentDate.setDate(currentDate.getDate() + 1);
}
console.log(between);

我也试过这段代码,但没有得到任何有用的输出,但它给出了一个错误:-

Uncaught TypeError: start.getTime is not a function

at HTMLButtonElement. (setschedule:227)

at HTMLButtonElement.dispatch (jquery-1.12.4.js:5226)

at HTMLButtonElement.elemData.handle (jquery-1.12.4.js:4878)

我需要的输出是:-

 [Friday, 06-01-2018,
  Saturday, 06-02-2018,
  ......,
  ......, //further till end date
 ]

我怎样才能得到我的输出任何帮助都将不胜感激。谢谢。

最佳答案

构建数组后,使用 .pop() 删除最后一个元素,并使用 .shift() 删除第一个元素。那应该只剩下介于两者之间的日期。

关于javascript - 如何在 jQuery 中仅打印两个特定日期之间的工作日日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50467801/

相关文章:

javascript - 如何添加类似于 Yahoo! 的底部边框当你滚动页面?

javascript - mirth javascript 翻译返回错误

javascript - 仅当选中特定数量的复选框时才自动提交表单

javascript - 与同步 ajax 调用的返回值混淆

javascript - Use selected element when selector allow for multiple options

javascript 在不同的浏览器中表现不同

javascript - 关闭 Accordion 菜单的所有选项卡

javascript - 实现顺序回调执行

javascript - 仅启用当前工作日的多日期选择器

Firefox 3.5.7 中的 jQuery Ajax 响应失败