当前位置: 代码迷 >> Eclipse >> 求算法:两个日期区间中判断是否有存在周四上午1点到5点!
  详细解决方案

求算法:两个日期区间中判断是否有存在周四上午1点到5点!

热度:7142   发布时间:2013-02-25 21:52:49.0
求算法:两个日期区间中判断是否有存在周四下午1点到5点!!
本帖最后由 AMIEugene 于 2013-01-31 10:18:11 编辑
传进来的2个String参数
可能是:“2013-01-31 09:00:00”,“2013-02-01 17:00:00”
也可能是:“2013-01-31 09:00:00”,“2013-02-06 17:00:00”
还可能是:“2013-01-31 09:00:00”,“2013-01-31 17:00:00”

我要判断这2个时间区间内是否包含周四13点到17点间。请问这个要怎么写啊??
try{
Calendar cal1=Calendar.getInstance();
Calendar cal2=Calendar.getInstance();
String s1="2013-01-31 09:00:00";
String s2="2013-02-01 17:00:00";

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cal1.setTime(sdf.parse(s1));
cal2.setTime(sdf.parse(s2));
int d1=cal1.get(Calendar.DAY_OF_WEEK);
int d2=cal2.get(Calendar.DAY_OF_WEEK);

int h1=cal1.get(Calendar.HOUR_OF_DAY);
int h2=cal2.get(Calendar.HOUR_OF_DAY);
System.out.println(d1+"  "+d2);
if(d1<=5 && d2>=5){
if(h1<=13 && h2>=17){
System.out.println("Successfully");
}
}
}catch(Exception e){
e.printStackTrace();
throw e;
}
引用:
引用:引用:引用:引用:还有其他办法吗???
你是要包含周四13点到17点这4个小时,还是只要包含就可以了。。。

是在这4小时之内的

你这考虑情况挺多的,例如 周四15点 到 下周四的15点,符合条件么。。。

你说……

你没明白我的意思。。。
  相关解决方案