1

I am developing a client-server mobile app (e-shopping), and can't decide what time source to use when displaying estimated package arrival time to the client. I am leaning towards retrieving a time value generated on the server and converting it to the device time zone to work around cases when time on the client's device is set incorrectly. However, the time zone on the device may also be set differently. Is there any generally accepted good practice regarding that ?

user2082616
  • 195
  • 1
  • 17

2 Answers2

2

Timestamps such as the ones you describe should be stored in terms of UTC (Coordinated Universal Time) on your server

  1. Generate UTC-based values on your server - which are independent of the server's time zone setting.

  2. Transmit those UTC-based timestamp to your client in a machine-readable format that preserves the context that the timestamp is in UTC. Preferably, ISO-8601 timestamps such as 2018-05-09T18:00Z (the Z indicates UTC).

  3. On the client device, convert that timestamp to the desired time zone. In the case of mobile devices, choosing the device's time zone is reasonable. It would be quite unreasonable IMHO to concern yourself with whether or not the client's time zone was set correctly. The time zone is a user-controlled preference. If it's set to some other time zone, then that is the time zone that should be used. You should not try to overcompensate.

  4. Format the timestamp as a string that is human-readable, using the preferred localization settings of the client device, and show that to the user.

Much more on this topic is already written. Start here.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
1

Store and persist the estimated time with your servertime and recalculate it to the devicetime in the app itself. So your data remains consistent in the storage/DB but every user has his time zone displayed.

jdickel
  • 1,437
  • 1
  • 11
  • 21