The question of time judgment

Source: Internet
Author: User
A1 2014-10-1 10:00:00
A2 2014-10-2 14:00:00
B1 2014-10-4 13:00:00
B2 2014-10-5 15:00:00

A1 is start time, A2 is end time, B1 is start time, B2 is end time
Now there's time C1-C2

How to Judge C1-c2, if in A1-A2 or b1-b2 inside or have cross, appear the box hint.


Reply to discussion (solution)

Convert to timestamp and compare size

Observe a fact

$ar = Array (  ' A1 ' = ' 2014-10-1 10:00:00 ',  ' A2 ' = ' 2014-10-2 ' 14:00:00 ',  ' B1 ' = ' 2014-10-4 13:00:00 ',  ' B2 ' = ' 2014-10-5 15:00:00 ',); $ar [' C1 '] = ' 2014-10-3 13:00:00 '; $ar [' C2 '] = ' 2014-10-5 13:00:00 '; Asort ($ar); Print_r ($ar);
Array (    [A1] = 2014-10-1 10:00:00    [A2] = 2014-10-2 14:00:00    [C1] = 2014-10-3 13:00:00    [B1] =& Gt 2014-10-4 13:00:00    [C2] = 2014-10-5 13:00:00    [B2] = 2014-10-5 15:00:00)
According to the key name can be accurately judged out of it?

Observe a fact

$ar = Array (  ' A1 ' = ' 2014-10-1 10:00:00 ',  ' A2 ' = ' 2014-10-2 ' 14:00:00 ',  ' B1 ' = ' 2014-10-4 13:00:00 ',  ' B2 ' = ' 2014-10-5 15:00:00 ',); $ar [' C1 '] = ' 2014-10-3 13:00:00 '; $ar [' C2 '] = ' 2014-10-5 13:00:00 '; Asort ($ar); Print_r ($ar);
Array (    [A1] = 2014-10-1 10:00:00    [A2] = 2014-10-2 14:00:00    [C1] = 2014-10-3 13:00:00    [ B1] = 2014-10-4 13:00:00    [C2] = 2014-10-5 13:00:00    [B2] = 2014-10-5 15:00:00)
According to the key name can be accurately judged out of it?



This is an example where the actual data is a bunch of arrays

No matter how much data you have, the algorithm is constant.
As long as you check the key names in turn, the start and end of the group are not adjacent to each other, with cross or nested

The reason for not writing specific code is that your situation is much more complicated than the example, and you can't put it up. The key is understanding.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.