django 1.4 how to automatically get user's timezone from client

前端 未结 5 967
误落风尘
误落风尘 2020-12-01 21:17

I would like to know if there is a way to automatically retrieve user\'s timezone from client. Especially during login.

I tried to add this in the login page (using

5条回答
  •  悲哀的现实
    2020-12-01 21:35

    From the documentation:

    Selecting the current time zone

    The current time zone is the equivalent of the current locale for translations. However, there's no equivalent of the Accept-Language HTTP header that Django could use to determine the user's time zone automatically. Instead, Django provides time zone selection functions. Use them to build the time zone selection logic that makes sense for you.

    You can try setting timezone cookie via javascript by utilizing getTimezoneOffset function or try to do some geoip magic and figure timezone by location. Probably the most reliable way would be to ask the user directly and save this information in user profile/session.

提交回复
热议问题