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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Possible using ICronTrigger.CronExpressionString
CronScheduleBuilder csb = CronScheduleBuilder
.WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 12, 0);
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(csb)
.Build();
string cronExpression = trigger.CronExpressionString;
回答2:
Using Ian answer, I have created a small extension method. Hopefully it will be useful for someone else...
public static class QuartzExtentionMethods
{
public static string ToCronString(this CronScheduleBuilder cronSchedule)
{
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(cronSchedule)
.Build();
return trigger.CronExpressionString;
}
}