Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Friends,

I have an issue regarding DateTime. On my page, I am showing date by using Javascript, when I save something according to that datetime, it saves according to Server time. It is causing an issue for me. Suppose a user is in India and server is in US, he can see the datetime as per his browser. But when he saves the value, it is according to server time, which is 12 hours less than India time.

Please let me know how I can come up of this issue.

Updated 25-Apr-11 19:50pm
Ankur\m/ 26-Apr-11 1:30am    
You will have to show your code on why it is not accepting JavaScript time.

What's the problem? You need to know not just the time by client watch but also its time zone, can be requested during creation of account or something like that.

Alternatively, you can ignore local client time and calculate all times by the server time only. It depends on your requirements.

In both cases, it's convenient to do all time calculation by converting all times into Coordinated Universal Time using System.DateTime.ToUniversalTime. If you need to present time on the page using client's local time, you can do it while generating a page individually for each time zone using System.DateTime.ToLocalTime. Again, you will need to know a time zone of each client.

See for more information:[^].

Share this answer
Prasanta_Prince 26-Apr-11 3:09am    
Good One 5 For that.
Sergey Alexandrovich Kryukov 26-Apr-11 11:33am    
Thank you, Prasanta.
You might want to pass your value from the client to the server - don't let the server save a default date.
You can also consider using UTC datetimes to help avoid this problem.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900