There is a static class under Quartz namespace which has two methods receiving a Func<DateTimeOffset>
that you can use to return your NTP tunned date/time. It is the "official" Quartz date/time source, and is implemented to allow easy unit testing, but could also be used to customize the date/time. Here is a a sample usage:
SystemTime.Now = () => {
//return your custom datetime here
/*
var ntpTime = new NtpTime(server);
return ntpTime.NowDateTimeOffset;
*/
};
SystemTime.UtcNow = () => {
//return your custom datetime here
/*
var ntpTime = new NtpTime(server);
return ntpTime.UtcNowDateTimeOffset;
*/
};
Notice the code above will not compile, you need to implement your own method of getting the current DateTimeOffset for both Now
and UtcNow
. There are many ways to get the time from a NTP, you can find some approaches here and here. I suggest that your implementation caches the current datetime and increment it locally instead of asking the ntp server on every call, for performance reasons.