简体   繁体   English

我如何检查日期时间的冲突

[英]How can i check conflict in date time

How could i know if there's a conflict , example i have here User Start time 7:00 AM End time 12:00 PM.我怎么知道是否存在冲突,例如我在这里有用户开始时间上午 7:00 结束时间下午 12:00。 Now if i add new Entry it should always CHECK the time.现在,如果我添加新条目,它应该始终检查时间。 It shouldn't be the same with the first one.应该和第一个不一样。 Meaning to say his time should be 12:00 PM Onwards.意思是说他的时间应该是下午 12:00 以后。 If his time is between 7-12.如果他的时间在7-12之间。 Example 11:00 AM this is CONFLICT since the first one has already workd in that time.示例 11:00 AM 这是冲突,因为第一个已经在那个时间工作。

To be more clear First entry .7:00 Am-12:00pm Second entry 12:00pm-3pm Third entry 3:00pm-7:00pm And so on.为了更清楚,第一次进入 0.7:00 am-12:00pm 第二次进入 12:00pm-3pm 第三次进入 3:00pm-7:00pm 依此类推。 Thank you to those who will help.感谢那些愿意提供帮助的人。

Just do some checks on the three dates you are using.只需对您使用的三个日期进行一些检查。 You should make an object for this but here is a simple code section of what it should look like.你应该为此创建一个对象,但这里有一个简单的代码部分,它应该是什么样子。

        var start = DateTime.Now;
        var end = start.AddHours(3);
        var newStart1 = start.AddHours(2);
        if(newStart1> start && end<= newStart1)
        {
            //valid time
        }
        else
        {
            throw new Exception("Invalid start time.");
        }

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

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