I have searched a lot on how to handle timezone in a web app. My application saves all dates as UTC in the database and returns UTC dates in json requests, so javascript proper handle conversions in the timezone of the user device.

But I had stuck with the problem of timezone when the user needs a report that is generated in the back-end and returned as a download file. Here I need a timezone to convert the dates.

How should I handle this problem?

  1. Should I ask the user his timezone (in the user profile) and always convert the dates in the back-end, regardless of which timezone his browser is?

  2. Should I let javascript handle timezone conversion for browser and ask the user timezone only for the reports?

  3. Should I use either option 1 or 2 and have some integration to discover the user timezone by his geolocation (or other option) and alert him when the application "thinks" he is in another timezone?

The main problem is that if the user moves to another timezone, the application will show some information in the wrong timezone until it is fixed in the user profile.

  • You can use Javascript to get the user's timezone. Use that to generate the download file. – Kasey Speakman May 16 '18 at 20:27
  • 1
    This depends so much on what those timestamps represent and what the purpose for these reports is. There's a huge difference between “your plane will land at 11am” (local time of the event relevant), “the video call is scheduled for 17:00 CEST/8am PDT” (local time relevant in multiple timezones), “our data centers in Manila and Paris will shutdown for maintenance at 04:00 UTC” (unambiguous timezone needed, little relevance in local time), …. It is not the case that the user's current timezone is always the correct timezone of a report. – amon May 16 '18 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.