/*
* 比较时间一是否在时间二的范围之内
* param nowTime 时间一
* param cTime 时间范围中心
* param h_m_s 选择时分秒,年月日
* param range 范围数值
* author 张亮
*
*/
public static boolean timeCompare(Date nowTime ,Date cTime ,String h_m_s,int range ){
boolean flag = false;
int key=0;
Calendar cnow = Calendar.getInstance();
Calendar ctime = Calendar.getInstance();
Calendar ctimebegin = Calendar.getInstance();
Calendar ctimeend = Calendar.getInstance();
cnow.setTime(nowTime);
ctime.setTime(cTime);
ctimebegin.setTime(cTime);
ctimeend .setTime(cTime);
if("hour".equals(h_m_s)||"HOUR".equals(h_m_s))
{
key=1;
}
if("MINUTE".equals(h_m_s)||"minute".equals(h_m_s))
{
key=2;
}
if("SECOND".equals(h_m_s)||"second".equals(h_m_s))
{
key=3;
}
if("YEAR".equals(h_m_s)||"year".equals(h_m_s))
{
key=4;
}
if("MONTH".equals(h_m_s)||"mouth".equals(h_m_s))
{
key=5;
}
if("DAY".equals(h_m_s)||"day".equals(h_m_s))
{
key=6;
}
switch (key) {
case 1:
ctimebegin.add(Calendar.HOUR,0-range);
ctimeend.add(Calendar.HOUR,range);
break;
case 2:
ctimebegin.add(Calendar.MINUTE,0-range);
ctimeend.add(Calendar.MINUTE,range);
break;
case 3:
ctimebegin.add(Calendar.SECOND,0-range);
ctimeend.add(Calendar.SECOND,range);
break;
case 4:
ctimebegin.add(Calendar.YEAR,0-range);
ctimeend.add(Calendar.YEAR,range);
break;
case 5:
ctimebegin.add(Calendar.MONTH,0-range);
ctimeend.add(Calendar.MONTH,range);
case 6:
ctimebegin.add(Calendar.DATE,0-range);
ctimeend.add(Calendar.DATE,range);
break;
default:
break;
}
Date cbegin = ctimebegin.getTime();
Date cend = ctimeend.getTime();
if(nowTime.compareTo(cbegin)>0&&nowTime.compareTo(cend) < 0){
flag=true;
}
return flag;
}
* 比较时间一是否在时间二的范围之内
* param nowTime 时间一
* param cTime 时间范围中心
* param h_m_s 选择时分秒,年月日
* param range 范围数值
* author 张亮
*
*/
public static boolean timeCompare(Date nowTime ,Date cTime ,String h_m_s,int range ){
boolean flag = false;
int key=0;
Calendar cnow = Calendar.getInstance();
Calendar ctime = Calendar.getInstance();
Calendar ctimebegin = Calendar.getInstance();
Calendar ctimeend = Calendar.getInstance();
cnow.setTime(nowTime);
ctime.setTime(cTime);
ctimebegin.setTime(cTime);
ctimeend .setTime(cTime);
if("hour".equals(h_m_s)||"HOUR".equals(h_m_s))
{
key=1;
}
if("MINUTE".equals(h_m_s)||"minute".equals(h_m_s))
{
key=2;
}
if("SECOND".equals(h_m_s)||"second".equals(h_m_s))
{
key=3;
}
if("YEAR".equals(h_m_s)||"year".equals(h_m_s))
{
key=4;
}
if("MONTH".equals(h_m_s)||"mouth".equals(h_m_s))
{
key=5;
}
if("DAY".equals(h_m_s)||"day".equals(h_m_s))
{
key=6;
}
switch (key) {
case 1:
ctimebegin.add(Calendar.HOUR,0-range);
ctimeend.add(Calendar.HOUR,range);
break;
case 2:
ctimebegin.add(Calendar.MINUTE,0-range);
ctimeend.add(Calendar.MINUTE,range);
break;
case 3:
ctimebegin.add(Calendar.SECOND,0-range);
ctimeend.add(Calendar.SECOND,range);
break;
case 4:
ctimebegin.add(Calendar.YEAR,0-range);
ctimeend.add(Calendar.YEAR,range);
break;
case 5:
ctimebegin.add(Calendar.MONTH,0-range);
ctimeend.add(Calendar.MONTH,range);
case 6:
ctimebegin.add(Calendar.DATE,0-range);
ctimeend.add(Calendar.DATE,range);
break;
default:
break;
}
Date cbegin = ctimebegin.getTime();
Date cend = ctimeend.getTime();
if(nowTime.compareTo(cbegin)>0&&nowTime.compareTo(cend) < 0){
flag=true;
}
return flag;
}