@Component
@EnableScheduling
public class TimerTask {
@Autowired
private EmployeeDao employeeDao;
//每天0点0分0秒执行一次
//@Scheduled(cron = "0 61 23 * * *")
//从左到右用空格隔开分别是:秒 分 时 日 月 周 年(可省略)
//第一个位置:Seconds 秒:区间 0-59 秒,代表一分钟内的秒数。
//第二个位置:Minutes 分:区间 0-59 分,代表一小时内的分钟数。
//第三个位置:Hours 时:区间 0-23 时,代表一天中的小时数。
//第四个位置:Day of month 日:区间 1-31 (?根据每月有多少天来),代表一月中的多少号。
//第五个位置:Month 月:区间 1-12 ,代表一年中的月份。
//第六个位置:Day of week 周:区间 1-7或者英文星期的缩写,代表星期几
@Scheduled(cron = "0 61 23 * * *")
public void task() {
Date dNow = new Date(); //当前时间
Date dBefore = new Date();
Calendar calendar = Calendar.getInstance(); //得到日历
calendar.setTime(dNow);//把当前时间赋给日历
calendar.add(Calendar.MONTH, -3); //设置为前3月
dBefore = calendar.getTime(); //得到前3月的时间
// List employees = employeeDao.delEmpByDate(dBefore);
// System.out.println(employees);
System.out.println(“定时任务…”);
}
}