简体   繁体   English

如何在时刻js中将星期几与实际日期进行比较?

[英]How to compare day of the week with actual date in moment js?

I'm relatively new to moment js. 我对js而言相对较新。 And I have a problem with the concept of time manipulation and comparison in moment JS. 而且我对时刻JS中的时间操纵和比较的概念有疑问。 What I want to do is compare times of 2 events. 我想做的是比较2个事件的时间。

First event is an actual event, like work hours. 第一个事件是实际事件,例如工作时间。 This has a start and end time. 这具有开始时间和结束时间。

Second event is a re-occurring event, like overtime hours for a company. 第二事件是重复发生的事件,例如公司的加班时间。 This also has a start time and end time, but the days may vary. 这也有开始时间和结束时间,但是日期可能会有所不同。

For example: from Monday 11:00PM to Tuesday 7:00AM is considered "overtime". 例如:从星期一11:00 PM到星期二7:00 AM被视为“加班”。 But I worked from Monday 9:00PM to Tuesday 6:00AM. 但是我的工作时间是从星期一9:00 PM到星期二6:00 AM。

How would i go about comparing these times? 我将如何比较这些时间? I need to compare them and separate the "overtime hours" from the "normal hours" and use these later. 我需要比较它们,将“加班时间”与“正常时间”分开,以后再使用。

Moment offers getter and setter methods to access certain parameters for comparison. Moment提供了getter和setter方法来访问某些参数进行比较。 Here is a basic approach to check if overhours and events happen on the same day of the week: 这是检查加班和事件是否在一周的同一天发生的一种基本方法:

if (moment(overhourDate).weekday() === moment(eventDate).weekday()) { 
    whatever(); 
}

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

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