Is it possible using the Quartz .NET assembly to generate a cron expression? I saw that the CronScheduleBuilder
class has a private member cronExpression
which is essentially what I am looking for. Is there any other way to get the cron expression itself?
Using Cron TriggersQuartz supports Cron-like expressions for specifying timers in a handy format.
A Cron Expressions quartz. Trigger. A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule. These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.
CronMaker is a simple application which helps you to build cron expressions. CronMaker uses Quartz open source scheduler. Generated expressions are based on Quartz cron format. For your feedback send email to [email protected]. Generate cron expression.
A question mark ( ? ) is allowed in the day-of-month and day-of-week fields. It is used to specify “no specific value,” which is useful when you need to specify something in one of these two fields, but not in the other.
Possible using ICronTrigger.CronExpressionString
CronScheduleBuilder csb = CronScheduleBuilder
.WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 12, 0);
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(csb)
.Build();
string cronExpression = trigger.CronExpressionString;
Using Ian answer, I have created a small extension method. Hopefully it will be useful for someone else...
public static class QuartzExtensionMethods
{
public static string ToCronString(this CronScheduleBuilder cronSchedule)
{
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(cronSchedule)
.Build();
return trigger.CronExpressionString;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With