CronExpression
==========================
cron表达式是由6个必需的字段和一个可选字段空格分隔
[second minute hour Day-of-month month Day-of-Week [year]]
?: 特定值
*: 所有值, 每(分/时/秒)
L: 每周最后一天(周六), 每月最后一天(1月31号|2月28号)
,: 列表
#: 每月第几周
-: 范围
/: 间隔
W: 最接近的周一到周五.如果15W是周六,则会在周六前一天周五执行, 如果15W是周日,则在下周一执行,如果15W是周二,则在周二执行, 如果1W是周六, 因为周六是上个月的周,因此会在下周一执行.
月份与数字映射 和 星期与数字映射:
monthMap.put("JAN", Integer.valueOf(0));
monthMap.put("FEB", Integer.valueOf(1));
monthMap.put("MAR", Integer.valueOf(2));
monthMap.put("APR", Integer.valueOf(3));
monthMap.put("MAY", Integer.valueOf(4));
monthMap.put("JUN", Integer.valueOf(5));
monthMap.put("JUL", Integer.valueOf(6));
monthMap.put("AUG", Integer.valueOf(7));
monthMap.put("SEP", Integer.valueOf(8));
monthMap.put("OCT", Integer.valueOf(9));
monthMap.put("NOV", Integer.valueOf(10));
monthMap.put("DEC", Integer.valueOf(11));
dayMap.put("SUN", Integer.valueOf(1));
dayMap.put("MON", Integer.valueOf(2));
dayMap.put("TUE", Integer.valueOf(3));
dayMap.put("WED", Integer.valueOf(4));
dayMap.put("THU", Integer.valueOf(5));
dayMap.put("FRI", Integer.valueOf(6));
dayMap.put("SAT", Integer.valueOf(7));
字段使用:
字段 取值范围 可使用特殊字符
Seconds 0-59 , - * /
Minutes 0-59 , - * /
Hours 0-23 , - * /
Day-of-month 1-31 , - * ? / L W
Month 1-12 or JAN-DEC , - * /
Day-of-Week 1-7 or SUN-SAT , - * ? / L #
Year (Optional) empty, 1970-2199 , - * /
示例:
0 0/5 9-18 ? * 2-6 2011,2012 : 2011和2012年每月每周周一到周五每天09:00点到19:00点每隔5分钟执行.
0 0/1 2 ? * 6#3 : 每年每月第三个星期五2点每分钟执行,到3点结束.
0 0/1 2 1,L * ?: 每年每月1号和最后一天2点每分钟执行,到3点结束.