UTC 时间的 Hangfire CRON
Hangfire CRON in UTC time
我试图在我的 MVC 应用程序中配置一个每天从 00:00 开始的循环任务。我知道这可以通过 RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);
来实现。
现在我的问题是 hangfire cron 是基于 UTC 时间还是服务器本地时间工作。如果它在当地时间工作,有没有办法 运行 在 UTC 时间?我必须这样做,因为这将是一天结束的过程,所有计划任务都是根据我的数据库中的世界时间安排的。
要在 UTC
时区执行作业,您可以在定义作业时提供 TimeZoneInfo
作为 TimeZoneInfo.Utc
。
RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily, TimeZoneInfo.Utc);
要在本地时区执行作业,您可以使用 TimeZoneInfo.Local
。
要 运行 在特定时区而不是 UTC,请查找您想要的 TimeZoneInfo
。该任务将在 运行 午夜
var manager = new RecurringJobManager();
manager.AddOrUpdate("some-id", Job.FromExpression(() => Method()),
Cron.Daily(),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
RecurringJob.AddOrUpdate(() =>
homeCtrl.SendEmail(), Cron.Daily(),
TimeZoneInfo.Local);
// 12:00:00 AM
我试图在我的 MVC 应用程序中配置一个每天从 00:00 开始的循环任务。我知道这可以通过 RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);
来实现。
现在我的问题是 hangfire cron 是基于 UTC 时间还是服务器本地时间工作。如果它在当地时间工作,有没有办法 运行 在 UTC 时间?我必须这样做,因为这将是一天结束的过程,所有计划任务都是根据我的数据库中的世界时间安排的。
要在 UTC
时区执行作业,您可以在定义作业时提供 TimeZoneInfo
作为 TimeZoneInfo.Utc
。
RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily, TimeZoneInfo.Utc);
要在本地时区执行作业,您可以使用 TimeZoneInfo.Local
。
要 运行 在特定时区而不是 UTC,请查找您想要的 TimeZoneInfo
。该任务将在 运行 午夜
var manager = new RecurringJobManager();
manager.AddOrUpdate("some-id", Job.FromExpression(() => Method()),
Cron.Daily(),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
RecurringJob.AddOrUpdate(() =>
homeCtrl.SendEmail(), Cron.Daily(),
TimeZoneInfo.Local);
// 12:00:00 AM