Cronexpression_cronexpression rules
Special characters allowed for field allowed values
Seconds 0-59,-*/
Sub 0-59,-*/
Hours 0-23,-*/
Date 1-31,-*? /L W C
Month 1-12 or JAN-DEC,-*/
Week 1-7 or Sun-sat,-*? /L C #
Year (optional) leave blank, 1970-2099,-*/
Meaning of an expression
"0 15 10?" * * "trigger 10:15 every day"
"0 15 10 * *?" Daily 10:15 Trigger
"0 15 10 * *?" * "10:15 per day" trigger
"0 15 10 * *?" 2005 "2005-year daily 10:15 Trigger
"0 * 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:59 daily
"0 0/5 14 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily
"0 0/5 14,18 * *?" triggers every 5 minutes from 2 o'clock in the afternoon to 2:55 daily and from 6 o'clock in the afternoon to 6:55
"0 0-5 14 * *?" triggers every 1 minutes from 2 o'clock in the afternoon to 2:05 daily
"0 10,44 14?" 3 WED "2:10 and 2:44 triggers in Wednesday of every March
"0 15 10?" * Mon-fri "Monday to Friday 10:15 trigger
"0 15 10 15 *?" 15th 10:15 per month
"0 L *?" 10:15 on the last day of the month
"0 15 10?" * 6L "Last month of Friday 10:15 Trigger
"0 15 10?" * 6#3 "Monthly third Friday 10:15 trigger
The ' * ' character can be used for all fields and set to "*" in the "sub" field to mean "every minute".
The '? ' character can be used in the "Day" and "Week" fields. It is used to specify ' ambiguous values '. This is used when you need to specify one of these two fields instead of the other
To. In the following example, you can see its meaning.
The '-' character is used to specify a range of values, such as "10-12" in the "Hour" field for "10 point to 12 points".
The ', ' character specifies a number of values. For example, in the "Weeks" field is set to "Mon,wed,fri" means "The days Monday, Wednesday, and Friday".
The '/' character is used to specify the increment of a value. For example, the "Seconds" field is set to "0/15" for "No. 0, 15, 30, and 45 seconds". and "5/15" means "5th, 20, 35, and
50 ". The "*" character in front of '/' is equivalent to the specified starting at 0 seconds. Each field has a series of values that can start or end. For the seconds and minutes fields, the value range is 0 to
59, it is 0 to 23 for the hour field, 0 to 31 for the day field, and 1 to 12 for the month field. The "/" field is just to help you in the allowed values
The value from the beginning of "Nth" in the range. So for the "month" field, "7/6" is only meant to be opened in July instead of "every six months", please note the subtle differences.
The ' L ' character can be used in both the "Day" and "Week" fields. It is the abbreviation for "last", but it has different meanings in both fields. For example, "L" in the day field means "one months
The last day of the year "-for January is number 31st for February is 28th (not a leap year). In the "Weeks" field, it simply means "7" or "SAT", but if the "
Weeks "field is followed by a number, it means" the last one weeks of the month X "-for example," 6L "means" the last Friday of the month ". When you use the ' L ' option, specify the OK
The list or scope is very important, otherwise you will be confused by the result.
The ' W ' is available for the day field. Used to specify the most recent weekday (Monday to Friday) for the given date of the calendar. For example, you set the "Day" field to "15W", meaning: "The most recent working day from 15th of the month
"。 So if number 15th is Saturday, the trigger will be called at 14th, or Friday. If number 15th is Sunday, the trigger will be triggered at 16th, or Monday. If number 15th is Tuesday, then the day will touch
Hair However, if you set the "Day" field to "1W" and the number is Saturday, the trigger will be triggered in the next Monday, which is the 3rd number of the month, because it will not cross the range boundary of the value of the month. W
Characters can only be used when the value of the day field is a single day instead of a series of values.
' L ' and ' W ' can be combined for the ' Day ' field as ' LW ', meaning ' last working day of the month '.
The ' # ' character can be used in the "Weeks" field. The character denotes "week X of the month", such as "6#3", which represents the third Friday of the month (6 for Friday and the third for the month "#3"). Another example:
"2#1" = Represents the first Monday of the month and "4#5" = Fifth Wednesday of the month. Note If you specify "#5" that the month does not have a fifth "week X", the month is not triggered.
The ' C ' character can be used for the "Day" and "Week" fields, which are abbreviations for "calendar". It represents the value, if any, that is computed based on the associated calendar. If there is no date associated with
Calendar, it is equivalent to including all calendars. The day field value of 5C means "the first day of the calendar or after 5th," and the "Weeks" field value "1C" means "the first day of the calendar or
After Sunday. "
Valid characters are not case-sensitive for the month field and the weeks field.
Question mark (?) in Cronexpression The explanation
The official document mentions the question mark when it says:
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 if you are need to specify something in one of the "the" and "the" the other. See the examples below for clarification.
The general meaning is to say:
Question mark (?) It can be used in the date or weekday field to indicate ' no specific value ', which is used when you set a value for both fields. This is illustrated in the following example.
However, in the following example does not clearly explain what the role of this question mark, so I programmed to experiment, and concluded that:
1. As the official document explains, the question mark (?) The function is to indicate that the field ' has no specific value ';
2, asterisks (*) and other values, such as numbers, indicate a specific value for the field, except that the asterisk (*) represents all possible values;
3. Cronexpression the rules for date and week fields are that they must be mutually exclusive, that is, only one field must have a specific value, and the other field must be ' no specific value ';
4. Question mark (?) is used to mutually exclusive the date and week fields.
Based on the above conclusions, the following conditions can be explained:
1, when the week and date are * or numbers, error
Support for specifying both a day-of-week and a day-of-month parameter are not implemented.
That is, two fields cannot be specified by a specific value and must be mutually exclusive. The * is the same as the number, if you specify a specific number, it is the same error.
2, when the week and date are, error
'? ' can only is specfied for Day-of-month-or-day-of-week.
That is, two fields cannot have ' no specific value '.
This is the implementation of spring, there is no reason, spring is to specify that the two fields must be such mutually exclusive settings.
Unlike Unix's crontab settings, the crontab rule is that the date and day of the week are triggered as long as one is satisfied, so there is no mutex problem.
Spring's Cronexpression