Hi there, I would like to render timezone for user to display datetime as per that users time. In
setting.py, I have TIME_ZONE = ‘UTC’ and USE_TZ = True. For example, a user based in Europe/London will see time one hour behind because I set timezone to “utc”. I want to leave timezone as “UTC” and somehow determine user’s timezone in order to display via django templates.
I have tried to django template tags e.g. localtime, timezone but no luck. Is there easy way to determine user timezone and then display correct localtime whilst having TIME_ZONE = ‘UTC’?
Yes, you’ve seen it. Using the middleware requires asking the user their timezone which is not what I want to do.
A middleware is probably a good idea no matter what. The middleware will activate the thread local timezone context so that all localization “just works” throughout the request life cycle.
Additionally, a form available for the user is probably a good idea as well. Sometimes the inferred timezone will be wrong. And you want the user to always be able to properly set their timezone.