Java判断一个时间是否在另一个时间段内
来源:互联网 发布:汉诺塔问题的算法设计 编辑:程序博客网 时间:2024/05/19 22:01
需求:当时间在凌晨0点至0点5分之间程序不执行。
也就是实现判断当前时间点是否在00:00:00至00:05:00之间
方法:
Java代码 :
/**
* 判断时间是否在时间段内 *
* @param date
* 当前时间 yyyy-MM-dd HH:mm:ss
* @param strDateBegin
* 开始时间 00:00:00
* @param strDateEnd
* 结束时间 00:05:00
* @return
*/
public static boolean isInDate(Date date, String strDateBegin,
String strDateEnd) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate = sdf.format(date);
// 截取当前时间时分秒
int strDateH = Integer.parseInt(strDate.substring(11, 13));
int strDateM = Integer.parseInt(strDate.substring(14, 16));
int strDateS = Integer.parseInt(strDate.substring(17, 19));
// 截取开始时间时分秒
int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
// 截取结束时间时分秒
int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
// 当前时间小时数在开始时间和结束时间小时数之间
if (strDateH > strDateBeginH && strDateH < strDateEndH) {
return true;
// 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
&& strDateM <= strDateEndM) {
return true;
// 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM == strDateBeginM
&& strDateS >= strDateBeginS && strDateS <= strDateEndS) {
return true;
}
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM <= strDateEndM) {
return true;
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
} else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM == strDateEndM && strDateS <= strDateEndS) {
return true;
} else {
return false;
}
} else {
return false;
}
}
- Java判断一个时间是否在另一个时间段内
- Java时间判断:判断一个时间是否在一个时间段内
- js判断一个时间是否在一个时间段内
- js判断一个时间是不是在某个时间段内
- 判断一个时间点是否在一个时间段的方法
- Java学习之判断某一时间是否在指定时间段内
- 判断现在是否在这个时间段内
- 判断时间是否在时间段内
- 如何判断一个时间是否在当前的两小时内
- java判断当前时间是否在某一时间段内(eg:06:00~22:00)
- 判断当前时间是否在某一时间段内
- [iOS]判断当前时间是否在指定的时间段内
- 判断当前时间是否在一天的某个时间段内
- 判断是否在某一个时间段内的处理
- 判断当前时间是否在某个时间段内
- c# 判断时间是否在 某一时间段内
- SQL怎么查询一个时间包含在另外一个时间段内?
- 如何判断一个时间段是否和另一个时间段冲突?
- The type java.util.Map$Entry cannot be resolved. It is indirectly referenced
- 三峰记
- java中的static作用
- mysql事务处理
- HDOJ 1130 How Many Trees?(卡特兰数+大数乘除法)
- Java判断一个时间是否在另一个时间段内
- 哎呀,JSP小记_第一目
- 代码优化:将重复代码封装成函数(2)
- 7中排序算法c++版
- maven 教程三 仓库
- 编程常用子函数
- C++实现——杨辉三角
- 解决PowerDesigner中DBMS有关的设置问题
- Android学习笔记-----------内容提供者