dev6546
dev6546

Reputation: 1442

Quartz.net setting the timezone for ITrigger?

ITrigger cronTrigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .WithCronSchedule(0 0/1 * 1/1 * ? *)
            .Build();

This code sets the time to run an hour before I want it to, so rather than running at 1:40 it runs at 12:40. Can I set the timezone of Itrigger to work for uk time ?

Upvotes: 8

Views: 12577

Answers (3)

Kaptein Babbalas
Kaptein Babbalas

Reputation: 1108

Maybe a little cleaner:

ITrigger trigger = TriggerBuilder.Create()
                .StartNow()
                .WithCronSchedule("0 27 15 ? * MON-FRI *", x => x.InTimeZone(TimeZoneInfo.Utc))
                .Build();

Upvotes: 6

Satish Wadekar
Satish Wadekar

Reputation: 131

ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger3", "group1")
.WithCronSchedule(
  "Your CRON Expression comes here", 
  x => x.InTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Your Time Zone Id comes here"))
)
.ForJob("GUID / any unique combination ID comes here ")
.Build()

Upvotes: 13

Papa
Papa

Reputation: 1638

There should be a TimeZone option when creating your trigger. Something like this:

.inTimeZone(TimeZone.CurrentTimeZone);

The above will take the server's current timezone. If not a UK based server, this should work.

TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");

Here is the link: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06

Upvotes: 4

Related Questions