public String pkBySalesTurnover(Department accepetDepartment,Department raiseDepartment,DepartmentPK departmentPk){
//设置TimerTask
TimerTask task = new TimerTask() {
@SuppressWarnings("static-access")
@Override
public void run() {
Calendar calendar=Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DATE);
System.out.println("year"+year);
System.out.println("month-1--"+(month-1));
System.out.println("day--"+day);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH,(month-1));
int end=calendar.getActualMaximum(calendar.DAY_OF_MONTH);
int begin=calendar.getActualMinimum(calendar.DAY_OF_MONTH);
System.out.println("当前月第一天:"+begin+"--------"+"当前月份最后一天:"+end+"现在是几号:"+day);
if(end==day){
//是本月最后一天执行计算代码(未完成)
System.out.println("success");
}else{
System.out.println("false");
}
}
};
//设置执行时间
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
//定制每天的23:59:59执行,
calendar.set(year, month, day, 15, 45, 59);
Date date = calendar.getTime();
Timer timer = new Timer();
System.out.println(date);
//int period = 2 * 1000;
//每天的date时刻执行task,每隔2秒重复执行
//timer.schedule(task, date, period);
//每天的date时刻执行task, 仅执行一次
timer.schedule(task, date);
return SUCCESS;
}
java定时器每月月末自动执行
最新推荐文章于 2024-07-16 11:01:39 发布