当前位置:网站首页>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;
}
}
边栏推荐
- How to analyze fans' interests?
- Thinking on multi system architecture design
- VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard
- [slam] lvi-sam analysis - Overview
- C language: some self realization of string functions
- Implementation of simple upload function in PHP development
- mysql 为查询结果增加序号
- You must configure either the server or JDBC driver (via the ‘serverTimezone)
- SSLError
- DELL远程控制卡 使用ipmitools设置ipmi
猜你喜欢

【ARXIV2204】Vision Transformers for Single Image Dehazing

【ARXIV2204】Simple Baselines for Image Restoration

The default isolation level of MySQL is RR. Why does Alibaba and other large manufacturers change to RC?

HashSet add

21 day SQL punch in summary

C language classic 100 question exercise (1~21)

Test Development - UI testing in automated testing

【ARIXV2204】Neighborhood attention transformer
![[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme](/img/e3/f9c6bfdbcd5dffd406e3f1d2331050.png)
[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme

IDEA使用dev-tool实现热部署
随机推荐
自定义Json返回数据
BigDecimal 进行四舍五入 四舍六入和保留两位小数
Microservice failure mode and building elastic system
yandex robots txt
[computer level 3 information security] overview of information security assurance
Why is MD5 irreversible, but it may also be decrypted by MD5 free decryption website
C language classic 100 question exercise (1~21)
分享几种管理C程序中标志位的方法
Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions
Performance test classification
How to send and receive reports through outlook in FastReport VCL?
Mysql数据库索引(innodb引擎)
BeanUtils.copyProperties无法复制不同List集合问题解决 Lists.transform函数
Internal implementation principle of yymodel
YUV to uiimage
11.< tag-动态规划和子序列, 子数组>lt.115. 不同的子序列 + lt. 583. 两个字符串的删除操作 dbc
个人写的一个文件上传工具网站
How to analyze fans' interests?
Interpretation of afnetworking4.0 request principle
MySQL basic query