加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用python,自动确定用户当前时区的最准确方法是什么

发布时间:2020-12-16 23:14:02 所属栏目:Python 来源:网络整理
导读:我已经验证了dateutils.tz.tzlocal()在heroku上不起作用,即使它确实如此,它不会只是从计算机的操作系统中获取tz,而不是用户吗? 如果没有存储用户时区,有没有办法确定请求的来源? (我正在使用烧瓶) Twitter确实有一个设置来调整你的时区,但我想知道他们如何
我已经验证了dateutils.tz.tzlocal()在heroku上不起作用,即使它确实如此,它不会只是从计算机的操作系统中获取tz,而不是用户吗?

如果没有存储用户时区,有没有办法确定请求的来源? (我正在使用烧瓶)

Twitter确实有一个设置来调整你的时区,但我想知道他们如何确定默认值应该是什么以及当用户没有登录时它将如何工作.

解决方法

您可以使用 Javascript并在cookie中设置客户端的时区.您甚至可以使用AJAX请求,然后将偏移量发送到服务器并保存在客户端的会话中.
var offset = new Date().getTimezoneOffset();

Description

The time-zone offset is the difference,in minutes,between UTC and local time. Note that>this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example,if your time zone is UTC+10 (Australian Eastern Standard Time),-600 will be returned. Daylight savings time prevents this value from being a constant even for a given locale

Mozilla Javascript Reference: getTimezoneOffset

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读