判断时间是否在时间段内
来源:互联网 发布:太空船废墟矩阵芯片 编辑:程序博客网 时间:2024/05/05 10:44
/**
* 判断时间是否在时间段内
*
* @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);
System.out.println("---------0----------"+strDate);
// 截取当前时间时分秒
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) {
System.out.println("---------1----------");
return true;
// 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
&& strDateM <= strDateEndM) {
System.out.println("---------2----------");
return true;
// 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM == strDateBeginM
&& strDateS >= strDateBeginS && strDateS <= strDateEndS) {
System.out.println("---------3----------");
return true;
}
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM <= strDateEndM) {
System.out.println("---------4----------");
return true;
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
} else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM == strDateEndM && strDateS <= strDateEndS) {
System.out.println("---------5----------");
return true;
} else {
System.out.println("---------6----------");
return false;
}
} else {
System.out.println("---------7----------");
return false;
}
}
* 判断时间是否在时间段内
*
* @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);
System.out.println("---------0----------"+strDate);
// 截取当前时间时分秒
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) {
System.out.println("---------1----------");
return true;
// 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
&& strDateM <= strDateEndM) {
System.out.println("---------2----------");
return true;
// 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
} else if (strDateH == strDateBeginH && strDateM == strDateBeginM
&& strDateS >= strDateBeginS && strDateS <= strDateEndS) {
System.out.println("---------3----------");
return true;
}
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM <= strDateEndM) {
System.out.println("---------4----------");
return true;
// 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
} else if (strDateH >= strDateBeginH && strDateH == strDateEndH
&& strDateM == strDateEndM && strDateS <= strDateEndS) {
System.out.println("---------5----------");
return true;
} else {
System.out.println("---------6----------");
return false;
}
} else {
System.out.println("---------7----------");
return false;
}
}
0 0
- 判断时间是否在时间段内
- Java时间判断:判断一个时间是否在一个时间段内
- 判断当前时间是否在某一时间段内
- [iOS]判断当前时间是否在指定的时间段内
- 判断当前时间是否在一天的某个时间段内
- 判断当前时间是否在某个时间段内
- c# 判断时间是否在 某一时间段内
- 判断现在是否在这个时间段内
- 判断当前时间是否在某多个时间段
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
- java判断当前时间是否在某一时间段内(eg:06:00~22:00)
- iOS-OC-判断某个时间是否处于某个时间段内
- iOS 判断当前时间是否处于某个时间段内
- Eclipse构建Maven项目
- IO复用
- Shell脚本实现文件的互斥访问
- Last_SQL_Error: Could not execute Update_rows event on table eip_fileservice.T_FILE_LOCATION; Can't
- [深入浅出Cocoa]iOS网络编程之CFNetwork
- 判断时间是否在时间段内
- ssh密钥与git
- android 6.0 棉花糖 运行时权限
- Winfrom使用dotnetCHARTING动态生成图片
- 当前技术学习目标 -- 时间线
- 虚幻4 删除Actor渲染线程和主线程的过程
- ....conflicts with existing, non-compatible bean definition of same name and class
- 利用vitamio Mediaplayer 自定义了一个播放器
- c++11多线程学习