我想写一个cronExpression 每个星期1到星期5的早上8:00到下午17:00,每隔10分钟执行一次。请问这个cronExpression该怎么写?

解决方案 »

  1.   

    字段   允许值   允许的特殊字符 
    秒    0-59    , - * / 
    分    0-59    , - * / 
    小时    0-23    , - * / 
    日期    1-31    , - * ? / L W C 
    月份    1-12 或者 JAN-DEC    , - * / 
    星期    1-7 或者 SUN-SAT    , - * ? / L C # 
    年(可选)    留空, 1970-2099    , - * / 


    表达式    意义 
    "0 0 12 * * ?"                每天中午12点触发 
    "0 15 10 ? * *"               每天上午10:15触发 
    "0 15 10 * * ?"               每天上午10:15触发 
    "0 15 10 * * ? *"             每天上午10:15触发 
    "0 15 10 * * ? 2005"          2005年的每天上午10:15触发 
    "0 * 14 * * ?"                在每天下午2点到下午2:59期间的每1分钟触发 
    "0 0/5 14 * * ?"              在每天下午2点到下午2:55期间的每5分钟触发  
    "0 0/5 14,18 * * ?"           在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发  
    "0 0-5 14 * * ?"              在每天下午2点到下午2:05期间的每1分钟触发 
    "0 10,44 14 ? 3 WED"          每年三月的星期三的下午2:10和2:44触发 
    "0 15 10 ? * MON-FRI"         周一至周五的上午10:15触发 
    "0 15 10 15 * ?"              每月15日上午10:15触发 
    "0 15 10 L * ?"               每月最后一日的上午10:15触发 
    "0 15 10 ? * 6L"              每月的最后一个星期五上午10:15触发   
    "0 15 10 ? * 6L 2002-2005"    2002年至2005年的每月的最后一个星期五上午10:15触发 
    "0 15 10 ? * 6#3"             每月的第三个星期五上午10:15触发自己看
      

  2.   

    一个Cron-表达式是一个由六至七个字段组成由空格分隔的字符串,其中6个字段是必须的而一个是可选的,如下: 
    字段名     允许的值     允许的特殊字符  
    秒     0-59     , - * /  
    分     0-59     , - * /  
    小时     0-23     , - * /  
    日     1-31     , - * ? / L W C  
    月     1-12 or JAN-DEC     , - * /  
    周几     1-7 or SUN-SAT     , - * ? / L C #  
    年 (可选字段)     empty, 1970-2099     , - * / 
     '*' 字符可以用于所有字段,在“分”字段中设为"*"表示"每一分钟"的含义。 '?' 字符可以用在“日”和“周几”字段. 它用来指定 '不明确的值'. 这在你需要指定这两个字段中的某一个值而不是另外一个的时候会被用到。在后面的例子中可以看到其含义。 '-' 字符被用来指定一个值的范围,比如在“小时”字段中设为"10-12"表示"10点到12点".  ',' 字符指定数个值。比如在“周几”字段中设为"MON,WED,FRI"表示"the days Monday, Wednesday, and Friday". '/' 字符用来指定一个值的的增加幅度. 比如在“秒”字段中设置为"0/15"表示"第0, 15, 30, 和 45秒"。而 "5/15"则表示"第5, 20, 35, 和 50". 在'/'前加"*"字符相当于指定从0秒开始. 每个字段都有一系列可以开始或结束的数值。对于“秒”和“分”字段来说,其数值范围为0到59,对于“小时”字段来说其为0到23, 对于“日”字段来说为0到31, 而对于“月”字段来说为1到12。"/"字段仅仅只是帮助你在允许的数值范围内从开始"第n"的值。 因此 对于“月”字段来说"7/6"只是表示7月被开启而不是“每六个月”, 请注意其中微妙的差别。 'L'字符可用在“日”和“周几”这两个字段。它是"last"的缩写, 但是在这两个字段中有不同的含义。例如,“日”字段中的"L"表示"一个月中的最后一天" —— 对于一月就是31号对于二月来说就是28号(非闰年)。而在“周几”字段中, 它简单的表示"7" or "SAT",但是如果在“周几”字段中使用时跟在某个数字之后, 它表示"该月最后一个星期×" —— 比如"6L"表示"该月最后一个周五"。当使用'L'选项时,指定确定的列表或者范围非常重要,否则你会被结果搞糊涂的。 'W' 可用于“日”字段。用来指定历给定日期最近的工作日(周一到周五) 。比如你将“日”字段设为"15W",意为: "离该月15号最近的工作日"。因此如果15号为周六,触发器会在14号即周五调用。如果15号为周日, 触发器会在16号也就是周一触发。如果15号为周二,那么当天就会触发。然而如果你将“日”字段设为"1W", 而一号又是周六, 触发器会于下周一也就是当月的3号触发,因为它不会越过当月的值的范围边界。'W'字符只能用于“日”字段的值为单独的一天而不是一系列值的时候。 'L'和'W'可以组合用于“日”字段表示为'LW',意为"该月最后一个工作日"。 '#' 字符可用于“周几”字段。该字符表示“该月第几个周×”,比如"6#3"表示该月第三个周五( 6表示周五而"#3"该月第三个)。再比如: "2#1" = 表示该月第一个周一而 "4#5" = 该月第五个周三。注意如果你指定"#5"该月没有第五个“周×”,该月是不会触发的。 'C' 字符可用于“日”和“周几”字段,它是"calendar"的缩写。 它表示为基于相关的日历所计算出的值(如果有的话)。如果没有关联的日历, 那它等同于包含全部日历。“日”字段值为"5C"表示"日历中的第一天或者5号以后",“周几”字段值为"1C"则表示"日历中的第一天或者周日以后"。 对于“月份”字段和“周几”字段来说合法的字符都不是大小写敏感的。 下面是一些完整的例子: 
    表达式     含义  
    "0 0 12 * * ?"     每天中午十二点触发  
    "0 15 10 ? * *"     每天早上10:15触发  
    "0 15 10 * * ?"     每天早上10:15触发  
    "0 15 10 * * ? *"     每天早上10:15触发  
    "0 15 10 * * ? 2005"     2005年的每天早上10:15触发  
    "0 * 14 * * ?"     每天从下午2点开始到2点59分每分钟一次触发  
    "0 0/5 14 * * ?"     每天从下午2点开始到2:55分结束每5分钟一次触发  
    "0 0/5 14,18 * * ?"     每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发  
    "0 0-5 14 * * ?"     每天14:00至14:05每分钟一次触发  
    "0 10,44 14 ? 3 WED"     三月的每周三的14:10和14:44触发  
    "0 15 10 ? * MON-FRI"     每个周一、周二、周三、周四、周五的10:15触发  
    "0 15 10 15 * ?"     每月15号的10:15触发  
    "0 15 10 L * ?"     每月的最后一天的10:15触发  
    "0 15 10 ? * 6L"     每月最后一个周五的10:15触发  
    "0 15 10 ? * 6L"     每月最后一个周五的10:15触发  
    "0 15 10 ? * 6L 2002-2005"     2002年至2005年的每月最后一个周五的10:15触发  
    "0 15 10 ? * 6#3"     每月的第三个周五的10:15触发  
      

  3.   

    Spring--quartz中cronExpression配置说明 字段   允许值   允许的特殊字符 
    秒     0-59     , - * /  
    分     0-59     , - * /  
    小时     0-23     , - * /  
    日期     1-31     , - * ? / L W C  
    月份     1-12 或者 JAN-DEC     , - * /  
    星期     1-7 或者 SUN-SAT     , - * ? / L C #  
    年(可选)     留空, 1970-2099     , - * /  
    The '*' character is used to specify all values. For example, "*" in the minute field means "every minute". 
    “*”字符被用来指定所有的值。如:”*“在分钟的字段域里表示“每分钟”。 
    The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other. See the examples below for clarification. 
    “?”字符只在日期域和星期域中使用。它被用来指定“非明确的值”。当你需要通过在这两个域中的一个来指定一些东西的时候,它是有用的。看下面的例子你就会明白。 
    月份中的日期和星期中的日期这两个元素时互斥的一起应该通过设置一个问号(?)来表明不想设置那个字段The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12". 
    “-”字符被用来指定一个范围。如:“10-12”在小时域意味着“10点、11点、12点”。 The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday". 
    “,”字符被用来指定另外的值。如:“MON,WED,FRI”在星期域里表示”星期一、星期三、星期五”. The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety. The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results. L是‘last’的省略写法可以表示day-of-month和day-of-week域,但在两个字段中的意思不同,例如day-of-month域中表示一个月的最后一天,
    如果在day-of-week域表示‘7’或者‘SAT’,如果在day-of-week域中前面加上数字,它表示一个月的最后几天,例如‘6L’就表示一个月的最后一个
    星期五,The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days

    The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month". The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month. The 'C' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "calendar". This means values are calculated against the associated calendar, if any. If no calendar is associated, then it is equivalent to having an all-inclusive calendar. A value of "5C" in the day-of-month field means "the first day included by the calendar on or after the 5th". A value of "1C" in the day-of-week field means "the first day included by the calendar on or after sunday". 
    关于cronExpression的介绍:
      
    字段 允许值 允许的特殊字符 
    秒 0-59 , - * / 
    分 0-59 , - * / 
    小时 0-23 , - * / 
    日期 1-31 , - * ? / L W C 
    月份 1-12 或者 JAN-DEC , - * / 
    星期 1-7 或者 SUN-SAT , - * ? / L C # 
    年(可选) 留空, 1970-2099 , - * / 
    表达式意义 
    "0 0 12 * * ?" 每天中午12点触发 
    "0 15 10 ? * *" 每天上午10:15触发 
    "0 15 10 * * ?" 每天上午10:15触发 
    "0 15 10 * * ? *" 每天上午10:15触发 
    "0 15 10 * * ? 2005" 2005年的每天上午10:15触发 
    "0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发 
    "0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发 
    "0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发 
    "0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发 
    "0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发 
    "0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发 
    "0 15 10 15 * ?" 每月15日上午10:15触发 
    "0 15 10 L * ?" 每月最后一日的上午10:15触发 
    "0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发 
    "0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发 
    "0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发 
    每天早上6点 
    0 6 * * * 
    每两个小时 
    0 */2 * * * 
    晚上11点到早上8点之间每两个小时,早上八点 
    0 23-7/2,8 * * * 
    每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点 
    0 11 4 * 1-3 
    1月1日早上4点 
    0 4 1 1 *
    quartz的高级特性不仅如此 
    1 数据库存储 
    2 集群支持 
    3 数据库持久化任务,trigger 
    4 trigger 的停止,运行 
    5 任务的任意添加 
    6 比corntrigger 更详尽的任务安排 
    7 线程的内部数据交换