/**
* 判断巡检时间是否在当前日期后面一周内
* @param planTime
* @return
* @throws ParseException
*/
private boolean isAfterToSeven(Date plTime) throws ParseException
{
Date nowDate = new Date();
Calendar aCalendar = Calendar.getInstance();
aCalendar.setTime(nowDate);
int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
aCalendar.setTime(plTime);
int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
int between = day2 - day1;
if(between >= 7)
{
return true;
}
else
{
return false;
}
}
/**
* 判断当前日期是星期几
* @param pTime 需要判断的时间
* @return dayForWeek 判断结果
* @Exception 发生异常
*/
public static int dayForWeek(String pTime) throws Exception
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int dayForWeek = 0;
if(c.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
}
return dayForWeek;
}
/**
* 获取今天之后几天的时间
* @param d
* @param day
* @return
*/
public static String getDateAfter(Date d,int day)
{
Calendar now =Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE,now.get(Calendar.DATE)+day);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String time = sdf.format(now.getTime());
return time;
}
/**
* 获得两个日期间相差的天数
* @param endtime
* @param starttime
* @return
*/
public static long getsubdates(String endtime,String starttime){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
long days=0;
try {
Date d1 = df.parse(endtime);
Date d2 = df.parse(starttime);
long diff = d1.getTime() - d2.getTime();
days = diff / (1000 * 60 * 60 * 24);
} catch (Exception e) { }
return days;
}
/**
* 获取当前月的上一个月的时间
* @return
*/
public String getlastDate()
{
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -7);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
String time = format.format(c.getTime());
System.out.println(time);
return time;
}
/**
* 获取本月共有多少天
*/
private static void getMonDayNum() {
java.util.Calendar cal = java.util.Calendar.getInstance();
int maxDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
System.out.println(maxDay);
}