我想每天早上 8 点(UTC 时间)解雇一份工作。问题是触发器不尊重我告诉它的时间。
我的代码如下:
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(
s => s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8,0)))
.Build();
var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times)
Console.WriteLine(time.UtcDateTime);
输出是:
30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 10:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM
6日的时间改变的原因是夏令时从本周末开始。
我如何让它像我告诉它的那样在 UTC 时间上午 8 点触发?
编辑:这太疯狂了,它甚至可以使用 Cron 时间表:
ITrigger trigger = TriggerBuilder.Create()
.WithCronSchedule("0 0 8 * * ?")
.Build();
var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);
foreach (var time in times)
Console.WriteLine(time.UtcDateTime);
输出:
30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 9:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM