Snowy
Snowy

Reputation: 6132

Force Quartz.NET to Work in UTC?

This is kind of related to Quartz.NET - Shouldn't this unit test pass?, but not exactly.

I have a server in GMT-4 and one in GMT-7. They both use Quartz.NET v2.1.2.400. I need both server do the same thing at the same time (within a little tolerance) based on GMT, using this cron string:

0 0 5,12,17 * * ?

However, one server is executing the job this before the other server. I need them to both be in sync. I am using the code below. I think that Quartz calculates times/schedules in GMT internally but externally does localtime. I want it to be GMT all the time. How can I do that?

My current code looks like this:

var trigger = new CronTriggerImpl(mytriggername) { CronExpressionString = cronString };
var job = new JobDetailImpl(jobName, jobType);
Quartz.ScheduleJob(job, trigger);

Thanks.

Upvotes: 1

Views: 2571

Answers (1)

darrenmc
darrenmc

Reputation: 1781

There is a setTimeZone method in the java implementation of CronTrigger and a TimeZone property in the .NET implementaion.

You can then set the timezone for the trigger on both matchines to UTC.

Of course this will only work if the server clocks on your machines are synchronised in some way, using NTP or similar.

Upvotes: 3

Related Questions