Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 861
dev6546 Avatar asked Jul 31 '13 12:07

dev6546


Video Answer


3 Answers

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()
like image 173
Satish Wadekar Avatar answered Oct 16 '22 00:10

Satish Wadekar


Maybe a little cleaner:

ITrigger trigger = TriggerBuilder.Create()
                .StartNow()
                .WithCronSchedule("0 27 15 ? * MON-FRI *", x => x.InTimeZone(TimeZoneInfo.Utc))
                .Build();
like image 24
Kaptein Babbalas Avatar answered Oct 16 '22 01:10

Kaptein Babbalas


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

like image 29
Papa Avatar answered Oct 16 '22 01:10

Papa