0

如何安排后台作业在哥伦比亚时间每天晚上 9 点开始?我正在使用quartz.net

public class Program
    {
        static void Main(string[] args)
        {
            // construct a scheduler

            var schedulerFactory = new StdSchedulerFactory();
            var scheduler = schedulerFactory.GetScheduler();
            scheduler.Start();


            TimeZoneInfo colombianTimezone = TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time");     
            var colombianTimeNow = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local,
                                                            colombianTimezone);    

            var job = JobBuilder.Create<EmailsJob>().Build();
            var now = DateTime.Now;

            var trigger = TriggerBuilder.Create()
                            .StartAt(//INeedThisToStartEverydayat9pmColombianTime)
                            .WithSimpleSchedule(x => x.WithIntervalInHours(24).RepeatForever())
                            .Build();

            scheduler.ScheduleJob(job, trigger);
        }
    }

StartAt 方法采用 DateTimeOffset 对象。

请帮忙

4

2 回答 2

2

基于 Cron 的调度可能是满足您需求的更好选择。

TimeZoneInfo colombianTimezone = TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time");     

var job = JobBuilder.Create<EmailsJob>().Build();

var trigger = TriggerBuilder.Create()
                .WithCronSchedule("0 0 21 * * ?", x => x.InTimeZone(colombianTimezone))
                .Build();

scheduler.ScheduleJob(job, trigger);
于 2012-05-05T06:56:59.620 回答
1

这应该给你今天晚上 9 点的 DateTimeOffset,转换为 UniversalTime 以传递给石英。

TimeZoneInfo colombianTimezone = TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time");
DateTime columbianTime9pm = TimeZoneInfo.ConvertTime(DateTime.Today.AddHours(21), TimeZoneInfo.Local,
                                                colombianTimezone);
DateTimeOffset startAt = new DateTimeOffset(columbianTime9pm).ToUniversalTime();

我还没有测试过,但我认为这也会定义你想要的触发器。

TimeZoneInfo colombianTimezone = TimeZoneInfo.FindSystemTimeZoneById("SA Pacific Standard Time");
DateTime startTime = TimeZoneInfo.ConvertTime(DateTime.Today.AddHours(21), TimeZoneInfo.Local,
                                                colombianTimezone);
SimpleTrigger trigger = new SimpleTrigger("myTrigger",
                                            null,
                                            startTime,
                                            null,
                                            SimpleTrigger.RepeatIndefinitely,
                                            TimeSpan.FromHours(24));
于 2012-05-04T23:23:31.193 回答