max(a1,a2)<=min(b1,b2)
感谢!
var time1Ticks = Convert.ToDateTime("2016-10-01").Ticks;
var time2Ticks = Convert.ToDateTime("2016-11-01").Ticks;
var time3Ticks = Convert.ToDateTime("2016-02-01").Ticks;
var time4Ticks = Convert.ToDateTime("2016-11-01").Ticks;
用这个,然后加上比较就可以了。只是我的简单想法,多多交流。
怎么比较呢?
var new_start_time = Date.parse(new Date('2016-11-19 10:11:00')); var new_end_time = Date.parse(new Date('2016-11-19 12:20:20')); var start_time = Date.parse(new Date('2016-11-18 20:00:20')); var end_time = Date.parse(new Date('2016-11-19 09:57:40')); //new的时间段不在另一个时间段区间中 console.log(new_start_time > end_time,new_end_time > start_time);//true,true 不能满足 new_start_time = Date.parse(new Date('2016-11-19 10:11:00')); new_end_time = Date.parse(new Date('2016-11-19 12:20:20')); start_time = Date.parse(new Date('2016-11-18 20:00:20')); end_time = Date.parse(new Date('2016-11-19 19:57:40')); //new时间段在另一个时间段中 console.log(start_time <= new_start_time && new_start_time <= end_time);//true 可以满足 new_start_time = Date.parse(new Date('2016-11-19 10:11:00')); new_end_time = Date.parse(new Date('2016-11-20 08:20:20')); start_time = Date.parse(new Date('2016-11-19 11:00:20')); end_time = Date.parse(new Date('2016-11-19 23:57:40')); //new时间段在另一个时间段中 console.log(start_time <= new_start_time && new_start_time <= end_time);//false 不能满足 console.log(start_time <= new_end_time && new_end_time <= end_time);//false 不能满足
将a1a2b1b2全部由yyyyMMdd变成毫秒值得形式,a1,a2中的任意一天就是a1~a2毫秒值之间的随机数。然后判断是否>=b1并且<=b2.以天为增量的话就是毫秒值变成原a1+随机数*一天的毫秒。
开始大于另一个的结束.或者结束大于另一个的开始
//新时间段 var new_start_time = Date.parse(new Date('2016-11-19 10:11:00')); var new_end_time = Date.parse(new Date('2016-11-19 12:20:20')); var start_time = Date.parse(new Date('2016-11-18 20:00:20')); var end_time = Date.parse(new Date('2016-11-19 09:57:40')); new_start_time > end_time; //true new_end_time > start_time; //true 然而新时间段并不在另一个时间段中
@ahhg: (new_start_time>start_time&&new_start_time<end_time)
|| (new_end_time>start_time&&new_end_time<end_time)
你比较 A1与B1的diff与A1与A2的diff,diff1>=diff2,就在A2---B2之间啊