当前位置:网站首页>24小时内的时间段无交叉
24小时内的时间段无交叉
2022-07-28 05:17:00 【MusicCodeM】
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
代码
2:00 - 4:00 6:00- 8:00
思路就是将这些转化为日期 lcoalDateTime进行比较, 思路是这样的,代码没有测试。
/** * 判断是否 时间段是否重复, 重叠了返回 false , 没有重叠返回true * @Param startTime 输入的开始时间 * @Param endTime 输出的结束时间 * @Param isStartTime 对比的开始时间 * @Param isEndTime 对比的结束时间 * */
public static boolean isOverlap(String startTime, String endTime , String isStartTime, String isEndTime ){
//添加前缀 yyyy-MM-dd
String frontTime1 = "1970-01-01";
String frontTime2 = "1970-01-02";
startTime = frontTime1 +" "+startTime; // 197-01-01 23:00
//说明是一个是 在00点之前,,一个在00点之后 比如 23:00 - 3:00
if(startTime.compareTo(endTime) > 0 ){
endTime = frontTime2 + " " + endTime;
}else{
endTime = frontTime1 + " " + endTime;
}
isStartTime = frontTime1 +" "+isStartTime;
if(isStartTime.compareTo(isEndTime) > 0 ){
isEndTime = frontTime2 + " " + isEndTime;
}else{
isEndTime = frontTime1 + " " + isEndTime;
}
//字符串转localdateTime
LocalDateTime localStartTime= LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime localEndTime= LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime localIsStartTime= LocalDateTime.parse(isStartTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime localIsEndTime= LocalDateTime.parse(isEndTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//没有00的区别了 3:00 -8:00 4:00-6:00 3:00 -8:00 2:00-6:00 2:00-9:00 8:00 -5:00
// start < end isStart< end
if( ( localEndTime.isEqual(localIsStartTime) || localEndTime.isBefore(localIsStartTime) )
&& ( localStartTime.plusDays(1).isAfter(localIsEndTime) ) // 确保不能超过24小时
){
// 情况1 : 3:00 -8:00 8:00-9:00
return true;
}else if( ( localIsEndTime.isEqual(localStartTime) || localIsEndTime.isBefore(localStartTime) )
&& ( localIsStartTime.plusDays(1).isAfter(localEndTime) )
){
//9:00 -11:00 8:00-9:00
return true;
}else{
return false;
}
}
边栏推荐
- After ruoyi generates the code corresponding to the database, what should I do to make the following image look like
- PC side bug record
- Barbie q! How to analyze the new game app?
- JSON in JS (launch object deep copy)
- Flask Development & get/post request
- 7. < tag string and API trade-offs> supplement: Sword finger offer 05. replace spaces
- Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website
- 注册中心服务eureka 切换到 nocas遇到的问题
- Autoreleasepool problem summary
- Microservice failure mode and building elastic system
猜你喜欢
![[computer level 3 information security] overview of information security assurance](/img/f0/a72e61fda58ea93ca4e9db7274f6e3.png)
[computer level 3 information security] overview of information security assurance

How does Alibaba use DDD to split microservices?

Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website

Duoyu security browser will improve the security mode and make users browse more safely

How about ink cloud?

【idea插件神器】教你如何使用IDEA一键set实体类中所有属性

Redis 之布隆过滤器

How practical is the struct module? Learn a knowledge point immediately

The solution after the samesite by default cookies of Chrome browser 91 version are removed, and the solution that cross domain post requests in chrome cannot carry cookies

Simulink automatically generates STM32 code details
随机推荐
oracle查看锁表语句、解锁方法
Autoreleasepool problem summary
SSLError
Share several methods of managing flag bits in C program
First acquaintance with C language (1)
block yandex bot
How about ink cloud?
微服务故障模式与构建弹性系统
How does Alibaba use DDD to split microservices?
Struct模块到底有多实用?一个知识点立马学习
LocalDateTime去掉T,JSONField失效
Duoyu security browser will improve the security mode and make users browse more safely
[internal mental skill] - creation and destruction of function stack frame (C implementation)
PC端-bug记录
Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website
I've been in an outsourcing company for two years, and I feel like I'm going to die
Melt cloud x chat, create a "stress free social" habitat with sound
Dell remote control card uses ipmitools to set IPMI
个人写的一个文件上传工具网站
【ARXIV2203】SepViT: Separable Vision Transformer