Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Quartz expression

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use Quartz expressions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Quartz uses Cron expressions similar to those under Linux to define time rules. The Cron expression consists of 6 or 7 time fields separated by spaces, as shown in the following table:

Position

Time domain

Value range

Special value

one

Second

0-59

,-* /

two

Minute

0-59

,-* /

three

Hour

0-23

,-* /

four

Date

1: 31

,-*? / L W C

five

Month

1: 12

,-* /

six

Week

1-7

-*? / L C #

seven

Year (optional)

1: 31

,-* /

Asterisk (*): can be used in all fields to represent each time in the corresponding time domain, for example, in the minute field, it means "per minute"

Question mark (?): this character is used only in date and week fields and is usually specified as a "meaningless value", equivalent to a dot symbol.

Minus sign (-): indicates a range. If "10-12" is used in the hour field, it means from 10 to 12:00.

Comma (,): expresses a list value. If "MON,WED,FRI" is used in the week field, it represents Monday, Wednesday and Friday.

Slash (/): XUnix y represents an equal step sequence, where x is the starting value and y is the incremental step value. If you use 0ram 15 in the minute field, it means 0Magne15, which means 30 and 45 seconds, while in the minute field, 5Accord 15 means 5pd20, which is 35, and you can also use * / y, which is equivalent to 0Compy.

L: this character is used only in the date and week fields and stands for "Last", but it has different meanings in the two fields. L in the date field indicates the last day of the month, such as the 31st of January and the 28th of February in a non-leap year; if L is used in the week, it means Saturday, which is equivalent to 7. However, if L appears in the week field and is preceded by a numeric X, it means "the last X day of the month." for example, 6L represents the last Friday of the month.

W: this character can only appear in the date field and is a modification of the leading date, indicating the working day closest to that date. For example, 15W indicates the nearest working day to the 15th of the month. If the 15th of that month is Saturday, it matches Friday on the 14th; if Sunday, it matches Monday on the 16th; if the 15th is Tuesday, the result is Tuesday on the 15th. However, it must be noted that the associated matching date cannot cross the month, if you specify 1W, if the 1st is Saturday, the result will match the 3rd Monday, not the last day of last month. The W string can only specify a single date, not a date range

LW combination: you can combine LW in the date field, which means the last working day of the month

Pound sign (#): this character can only be used in the week field, indicating the working day of the month. For example, 6: 3 means the third Friday of the month (6 means Friday, and # 3 means the current third), while 4: 5 means the fifth Wednesday of the month. If there is no fifth Wednesday in the month, ignore it and not trigger it.

C: this character is used only in the date and week fields and stands for "Calendar". It means the date associated with the plan, and if the date is not associated, it is equivalent to all the dates in the calendar. For example, 5C is equivalent to the first day after the 5th of the calendar in the date field. 1C is equivalent to the first day after Sunday in the week field.

Cron expressions are not sensitive to the case of special characters, nor to the case of the abbreviation that represents the day of the week.

Example:

Expression

Description

0 012 *?

Run at 12:00 every day

0 15 10? * *

Run at 10:15 every day

0 15 10 *?

Run at 10:15 every day

0 15 10 *? *

Run at 10:15 every day

0 15 10 *? 2008

Run at 10:15 every day in 2008

0 * 14 *?

It runs every minute from 14:00 to 15:00 every day, starting at 14:00 and ending at 14:59.

0 0B 5 14 * *?

It runs every 5 minutes from 14:00 to 15:00 every day, starting at 14:00 and ending at 14:55.

0 010 5 14 14 18 * *?

It runs every 5 minutes from 14:00 to 15:00 and every 5 o'clock from 18:00 to 19:00 every day.

0 0-5 14 *?

Run every minute from 14: 00:00 to 14:05 every day.

0 10,44 14? 3 WED

It runs every minute from 14:10 to 14:44 on Wednesdays in March.

0 15 10? * MON-FRI

It runs at 10:15 on Mondays, Tuesdays, Thursdays and Fridays.

0 15 10 15 *?

It runs at 10:15 on the 15th of every month.

0 15 10 L *?

It runs at 10:15 on the last day of every month.

0 15 10? * 6L

It runs at 10:15 on the last Friday of every month.

0 15 10? * 6L 2007-2009

It runs at 10:15 on the last Friday of every month in 2007 and 2009.

0 15 10? * 6 3

It runs at 10:15 on the third Friday of every month.

Thank you for reading! This is the end of this article on "how to use Quartz expressions". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report