python - How to test datetime conversion with pytz and tzlocal? -
So I have datetime objects that I want to show to users in my local time.
Using the questions answered here, I have come up with a zinc filter to complete it:
to tzlocal import get_localzone import pytz def local_datetime ( Utc_dt): local_tz = Get_localzone () local_dt = utc_dt.replace (tzinfo = pytz.utc) .Stimazon (local_ties) local_dt.strftime ('% m /% d /% y @% I:% M% p') app. Ginja_nv.filter ['local_dt'] = local_detetime {{user.last_login_at | Local_dt}} # in my template I thought that every time someone sees the page (hence the filter) so that it will always be shown in the user's original time zone
This shows the correct on my development machine, but I want to ensure that get_localzone () is actually grabbing the user's local timezone and not always the server
My question is that I How to test it Can I have it working properly?
get_localzone () always back to your server's local timezone Used to be.
There is nothing in the HTTP headers of the request that can tell you the user's timezone, instead, the standard way to get close to it is to tell the user your preferred time zone.
For more discussion about this, see.
Comments
Post a Comment