【问题标题】:Angular - create a function the takes 2 dates and a day of the week and create an array of the the dates of the same days of the weekAngular - 创建一个需要 2 个日期和一周中的一天的函数,并创建一周中同一天的日期数组
【发布时间】:2021-08-10 17:58:19
【问题描述】:

我正在使用 Angular 和 Nodejs express 构建课程管理器 API,但我一直在试图弄清楚:

我试图弄清楚如何创建一个接收 2 个日期(时间范围 -> 1.1.2021 - 30.1.2021)和一个工作日(比如说星期一)的方法/函数。

并返回时间范围内所有星期一的数组。

示例: 课程开始日期:1.1.2021 课程结束日期:30.1.2021 上课日:周一

它会返回:[4.1.2021,11.1.2021,18.1.2021,25.1.2021,4.1.2021] - 这些是 1.1.2021 - 30.1.2021 时间范围内所有星期一的日期

有人可以给我一个提示吗?我尝试使用日期范围选择器,但无处可去。有没有我可以使用的内置函数?

enter image description here

【问题讨论】:

标签: node.js angular express date


【解决方案1】:

查看date-fns

eachDayOfInterval({start, end}).filter(z => getDay(z) === day)

其中startend 是普通的Date 对象,day 是工作日(0-星期日、1-星期一等)

【讨论】:

  • 顺便说一句,这个答案与 Angular 完全无关 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
  • 2013-11-22
  • 1970-01-01
  • 2021-08-24
相关资源
最近更新 更多