Till today I am using DateTime.Now; function to save the time and data of users. Well, at later stage I used JavaScript to get the client’s date and time to maintain Time Zone. But when I change my system’s date and time and try that JavaScript. It show the changed time of my computer. I need how to get clients correct current date and time value. How to get it.
Please do not exceed answer more than C# & JavaScripts.
On client, when client send a request with javascript, get new Date().toJSON() value and send it to server. toJSON() returns current client datetime in GMT+0000 timezone (Greenwich):
On server, in C#:
Above code is required, that time on client and on server has been synchronized with global clocks (internet timesource servers, for example). To avoid this problem you can calculate and save (in Session, for example) initial (on first request) difference between client and server clocks, and add this ‘difference’ to
maxandminvariables. This behaviour is simply to coding, and not showed in code above.