1

What is the best way to handle multiple time zones in the application ? The user can select the timezone that they are in. The user can be anywhere in the world. When displaying data the time has to be adjusted to the timezone that the user has selected. We have devices out in the field and they will be sending data, alerts etc. What would be the best way to store data in database ? Once data is stored then displaying will be straight forward.

user1860447
  • 1,316
  • 8
  • 25
  • 46
  • 1
    This is a very broad question; the main thing I'd say is *design them in from the very start*. Retrofitting code for timezone support is a pain. – Andy Turner Mar 16 '17 at 18:34
  • I'd store all the times in UTC and will store time zones for the users separately – borowis Mar 16 '17 at 18:39
  • 2
    @borowis - that advice is widely spread and needs to stop. UTC has many applications, but it is not an "always" thing. See the tz/dst best practices article (linked as dup) for more details. – Matt Johnson-Pint Mar 17 '17 at 18:02
  • nice to know, thanks, Matt! – borowis Mar 17 '17 at 20:59

1 Answers1

4

I would suggest storing all times in UTC format. Perform all your calculations and algorithms with the UTC time. You only care about timezones for display purposes. For a particular user, convert the UTC time to their preferred timezone.

Joe
  • 320
  • 1
  • 7
  • 4
    This advice is widely spread and needs to stop. UTC has many applications, but it is not an "always" thing. See the tz/dst best practices article (linked as dup) for more details. – Matt Johnson-Pint Mar 17 '17 at 18:02