I have an ASP.NET MVC app that stores all SQL DateTime in UTC, so that the time is consistent regardless of time zone that the client is hitting the site from.
Now, I want to re-display the correct time to the user, so any time I display a time in my View I use:
timeVariable.ToLocalTime();
However, .ToLocalTime() is based on the server, not the client.
Do I need to handle this in JavaScript on the client?
I probably could pass the time zone as part of the request and have the controller handle the offest, but I am assuming there is a better way to do this. Or isn’t there?
Thanks in advance for any help!
-Matt
Almost all sites that I have seen that translate time to local time ask the user to specify his or her timezone when creating an account. Gmail is one example but there are many others.
I’ve found that many solutions trying to use javascript or reverse-lookup on the IP address are prone to failure and edge cases.