python - How to test datetime conversion with pytz and tzlocal? -
python - How to test datetime conversion with pytz and tzlocal? -
so have datetime objects want show users in local time.
using answered questions on here, i've come jinja filter accomplish this:
from tzlocal import get_localzone import pytz def local_datetime(utc_dt): local_tz = get_localzone() local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz) homecoming local_dt.strftime('%m/%d/%y @ %i:%m %p') app.jinja_env.filters['local_dt'] = local_datetime {{ user.last_login_at|local_dt }} # in template
my thought run each time views page (hence filter) show in user's native timezone.
it shows right on development machine, i'd create sure get_localzone() grabbing user's local timezone , not server's.
my question is: how can test if working correctly?
get_localzone()
homecoming local timezone of server application running on.
there nil in http headers of request can tell user's timezone. instead, standard way of approaching inquire user tell preferred timezone.
see determining web user's time zone more give-and-take this.
python datetime flask jinja2 pytz
Comments
Post a Comment