比较当前时间是否在指定范围
2012-05-19 15:41
393 查看
//比较两个时间是否存在交集 public static boolean isInDates(String times){ int strDateBeginH = Integer.parseInt(times.split("-")[0].split(":")[0]); int strDateBeginM = Integer.parseInt(times.split("-")[0].split(":")[1]); int beginM = strDateBeginH*3600+strDateBeginM*60; System.out.println("开始时间 "+strDateBeginH+":"+strDateBeginM+" "+beginM); Date dt = new Date(); int strDateH = dt.getHours(); int strDateM = dt.getMinutes(); int thisM = strDateH*3600+strDateM*60; System.out.println("当前时间 "+strDateH+":"+strDateM+" "+thisM); int strDateEndH = Integer.parseInt(times.split("-")[1].split(":")[0]); int strDateEndM = Integer.parseInt(times.split("-")[1].split(":")[1]); int endM = strDateEndH*3600+strDateEndM*60; System.out.println("结束时间 "+strDateEndH+":"+strDateEndM+" "+endM); System.out.println("比较实际 ["+beginM+" "+thisM+" "+endM+"] "+(thisM>= beginM && thisM <= endM)); if(thisM>= beginM && thisM <= endM){ return true; }else{ return false; } } //比较两个时间是否存在交集 public static boolean isInDates_old(String times){ Date dt = new Date(); int strDateH = dt.getHours(); int strDateM = dt.getMinutes(); if(strDateH == 0 && strDateM == 0){ strDateH = 23;strDateM = 59; }else if(strDateH == 0){ strDateH = 24; }else if(strDateM == 0){ strDateH = strDateH-1;strDateM = 59; } int strDateBeginH = Integer.parseInt(times.split("-")[0].split(":")[0]); int strDateBeginM = Integer.parseInt(times.split("-")[0].split(":")[1]); int strDateEndH = Integer.parseInt(times.split("-")[1].split(":")[0]); int strDateEndM = Integer.parseInt(times.split("-")[1].split(":")[1]); if(strDateEndH == 0 && strDateEndM == 0){ strDateEndH = 23;strDateEndM = 59; }else if(strDateEndH == 0){ strDateEndH = 24; }else if(strDateEndM == 0){ strDateEndH = strDateEndH-1;strDateEndM = 59; } if((strDateH>=strDateBeginH && strDateM>=strDateBeginM && strDateH<=strDateEndH && strDateM<=strDateEndM)){ return true; }else{ return false; } }
相关文章推荐
- android获取当前系统时间,同时比较当前时间是否在一个时间段范围内
- JavaScript比较当前时间是否在指定时间段内的方法
- JS时间戳比较大小:对于一组时间戳(开始时间~结束时间)和另一组时间戳进行比较,用于判断被比较时间戳组是否在要求范围内
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- 判断是否为今年、是否为今天、是否为昨天,比较当前时间和from时间的差值
- 判断是否为今年、是否为今天、是否为昨天,比较当前时间和from时间的差值
- 判断当前时间是否在某个时间范围内
- js实现检测当前时间是否超过指定时间,而进行操作
- iOS 判断当前时间是否在一个时间范围内
- 判断当前时间是否在某个时间范围内:比如:在8:00~20:00
- 判断当前时间是否在一个时间段范围内
- Sql数据库时间和当前时间格式后比较是否相等
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- Java常用类:Data()的用法,获得当前日期和时间对象date 定义对象Date date1 = new Date(36000000);获得包含的日期和时间 比较date和date1是否相等
- NSString:创建,长度,取字符,是否以某字符串开头,结尾, 查找指定字符串的范围,截取,拼接,替换,比较,替换,数值转换,大小写转换
- Oracle判断当前时间是否在范围呢
- C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期
- java判断一个时间戳是否在指定时间范围内的方法
- js根据当前时间获取指定范围内的时间段日期
- 判断输入的时间格式和判断当前输入的时间是否在输入的时间范围内