前言:最近有个业务需求,需要做一个任务调度,其核心之一就是Cron表达式。
需求:做一个计划,由计划内容生成任务,要求在周一至周五08:00点生成任务。
表达式:0 0 8 ? * 1,2,3,4,5 * (错误的)
错误现象:明明设置的是周一至周五生成,但是却在周天生成了,而周五却没有生成。
翻找源码发现:标准时间前后差一天。
正确表达式:0 0 8 ? * 2,3,4,5,6 *
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Sunday.
*/
public final static int SUNDAY = 1;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Monday.
*/
public final static int MONDAY = 2;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Tuesday.
*/
public final static int TUESDAY = 3;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Wednesday.
*/
public final static int WEDNESDAY = 4;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Thursday.
*/
public final static int THURSDAY = 5;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Friday.
*/
public final static int FRIDAY = 6;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Saturday.
*/
public final static int SATURDAY = 7;