I am using a couple variables that store DateTime.Now for both database and web services purposes. Someone asked how the code will behave if the application gets deployed to machines in different time zones. The application will manipulate data from different time zones. How do I insure that no problems arise as a result of this?
Share
Let’s say a piece of data comes in from a different time zone. Your system gives it a time stamp that is the current time on your machine, and stores it.
Now a user at the location in the other time zone needs to look up when that transaction occurred, and compare it to something in a log file on their system. The time values won’t sync up, because their log is using their time and yours is using your time.
The typical solution is to store the times as universal time (also called Greenwich time). When you get a request from another time zone, you either convert the date back to that time zone’s time (so they can compare with their logs) or you let them know that you’re returning universal time, and they will have to convert themselves (or else switch to using universal time themselves if they aren’t already).
Switching to universal time will also deal with the issue of your application being deployed elsewhere, but the deeper issue of time zone comes up way before that.