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

What is the Cron expression like?

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "how Cron expressions are". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The task scheduling of Quartz.NET mainly depends on CronTrigger and Cron expressions. Cron has been in UNIX for a long time, and it has a strong and reliable scheduling capability. The CronTrigger class is also based on Cron scheduling capabilities.

CronTrigger uses Cron expressions. It has the flexibility to set up a variety of scheduled tasks, such as performing a task at 8: 00 a. M. from Monday to Friday. But while Cron expressions are powerful and flexible, they are also confusing and difficult to understand.

Cron format

The Cron expression is used to configure the CronTrigger instance. The Cron expression is a string consisting of 6 fields (subexpressions) and spaces.

So, for example, an cron expression string "00 10? * MON", which means "10:00 every Monday".

From the above list, you can clearly see that the values in all fields have a specific legal range, and each domain can be configured separately. For example, Day of week (the day of the week) must have a SUN-SAT or use special characters, so "010? * MON" can be changed to "MON-FRI", "MON, WED, FRI" or even "MON-WED,SAT".

Special character description

'*': means "each" in the domain. For example, * in the "Minutes" field represents every minute.

'?': used in day-of-month and day-of-week fields to mean "no value specified". This is useful when you need to specify values for one or two fields without setting other fields. For example, I want to put "10" in the day-of-month domain on a certain day of the month (for example, tenth), regardless of which day it is, and then "?" In day-of-week.

'-': specify a range, for example, "10-12" in the home domain, which means 10:00 to 12:00.

',': specify the added value, for example, "MON,WED,FRI" in the day-of-week field, which means "Monday, Wednesday, and Friday".

'/': there is no specific value to be used to specify the increment of the value. For example, if in the seconds field, '0max 15 seconds, it means "every 15 seconds, starting at 0."

'L': used only in day-of-month and day-of-week, this character is an abbreviation for "last", but has different meanings in the two domains. For example, the "L" in the day-of-month domain indicates the last day of the month, that is, the 31st of January and the 28th of February in a non-leap year. If it is used in day-of-week, it means "7" or "SAT". However, this character follows other values and represents "the last week XXX of the month". For example, "6L" or "FRIL" means the last Friday of this month. At the same time, it can also be used to specify the penultimate day of the last day of a month, for example, "Lmur3" indicates the penultimate day of the last day of a month. Note: when using the'L 'option, it is most important not to specify a list or range of values, otherwise it will lead to confusion.

'W': used to specify the closest day of a given day (Monday, Friday) in the day-of- domains domain. For example, "15W" means "what day is the nearest working day from the 15th of the month".

Indicates the day of the week in the middle of the month. For example, "6: 3" or "FRI#3" in the day-of-week domain means "the third Friday of the month".

Related examples

Note:'?' The influence of and'*'on day-of-week and day-of-month

That's all for "what Cron expressions are". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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