如何根据UTC偏移量选择时区? [英] How to pick a timezone based on UTC offset?

查看:66
本文介绍了如何根据UTC偏移量选择时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的问题.我正在解析Facebook用户数据,并且将时区作为数字获取:

i've got a silly problem. I'm parsing Facebook user data, and I get the timezone as a number:

时区:用户与UTC的时区偏移量

timezone: The user's timezone offset from UTC

对我来说('America/Argentina/Buenos_Aires')--3.

现在,如何将该数字转换为 pytz.timezone ?

Now, how can I convert that number to a pytz.timezone?

谢谢!

推荐答案

没有1:1的对应关系,因此如果不做一些必定无效的假设就无法做到这一点.

There's not a 1:1 correspondence, so there's no way to do it without making some assumptions that are bound to be invalid.

您可以创建自己的 tzinfo 类,可直接对偏移量进行编码,而无需尝试将其绑定到区域.

You can create your own tzinfo class that encodes the offset directly without trying to tie it back to a zone.

这篇关于如何根据UTC偏移量选择时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆