anthonypliu
anthonypliu

Reputation: 12437

Keeping my submitted client side datetime in sync with my timer job

I submit a datetime from my client side to my server. Lets say its 1:00pm California time. Upon the submission of this data, I parse the time and convert it UTC like so:

DateTime.SpecifyKind(DateTime.ParseExact(model.SessionStart, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture).ToUniversalTime(), DateTimeKind.Utc);

I have a timerjob running on the same server that checks for these dates that are less than the current time so my code runs when the session start time is at the right time.

How can I keep all these times in sync with my server so that if someone submits from california, or new york everything is converted properly and my timerjob will run correctly.

Upvotes: 0

Views: 608

Answers (1)

omer schleifer
omer schleifer

Reputation: 3935

I think a better approach for the auction will be to let the client send the server start time and end time in UTC, and let the server timers compare Utc time now to the auction start/end time. there is no need to use the local time of the server here at all.

The only local time to use, is in the client dispaly. any dealing with the server and within the server should be always in UTC only.

And as for time synchronization, you can use something like NODA time as suggested here by John Skeet: What would be the best way to synchronize my application's time with outside server's time?

Upvotes: 1

Related Questions