Create Cron Expression using Quartz .NET

扶醉桌前 提交于 2019-12-05 12:15:42
Ian R. O'Brien

Possible using ICronTrigger.CronExpressionString

CronScheduleBuilder csb = CronScheduleBuilder
    .WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 12, 0);

ICronTrigger trigger = (ICronTrigger)TriggerBuilder
    .Create()
    .WithSchedule(csb)
    .Build();

string cronExpression = trigger.CronExpressionString;
Thomas

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!