[英]hangfire BackgroundJob.Schedule is running on server time only. How do I fix this?
我在hangfire 上安排一個任務,但它不會在我的當地時間(印度標准時間)觸發。 如果我將其設置為 2030/3/3 10:00:00 am,它將僅在有 5 小時 30 分鍾差異的服務器時間觸發,而不是在我想要的正確時間觸發。
我試過做類似的事情
DateTime updatedDate = DateTime.Parse(datetime);
updatedDate = updatedDate.AddSeconds(+30);// add extra 30 sec
DateTime currentTime = TimeZoneInfo.ConvertTime(updatedDate, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
string jobid = BackgroundJob.Schedule<Tasks>(x => x.recurringService(), currentTime).ToString();
但它根本不起作用。 有人請告訴我一個方法。
我假設您的計算機設置為印度標准時間 (IST)。 我還假設datetime
字符串沒有指示時區。
在DateTime.Parse(datetime)
之后,變量updateDate
的“種類”應該等於DateTimeKind.Unspecified
。 請參閱Console.Write(updateData.Kind)
根據 Microsoft docs ,如果傳遞的參數TimeZoneInfo.ConvertTime
是DateTimeKind.Unspecified
,則假定為DateTimeKind.Local
(即 IST)。 這意味着ConverTime
正在從 IST 轉換為 IST,因此不會進行任何更改。
為此,您需要updateDate
為DateTimeKind.Utc
DateTime.SpecifyKind(updatedDate, DateTimeKind.Utc);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.