Reputation: 886
I have a website based on MVC and I am using DateTime.Now for time operations like countdowns. But sometimes there can be a difference between users' devices and the server. For example:
Device time: 12/4/2019 4:22:46 PM
Server time: 12/4/2019 4:22:38 PM
And this time difference is a huge problem for me. I've searched and couldn't find anything about it, but is there any way to get server's date and time?
PS: This can be done via javascript or jQuery, either.
Upvotes: 0
Views: 525
Reputation: 1196
You can use on the server side the DateTime.Now function and pass to the web page by inserting it into ViewData["Time"] and when you load the web page compare it with the javascript Date.Now() function on page load.
Upvotes: 2