如何在Python中使用datetime.tzinfo? [英] How to use datetime.tzinfo in Python?

查看:230
本文介绍了如何在Python中使用datetime.tzinfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用 datetime.tzinfo 模块。我必须将日期时间数据从UTC转换为本地时区,如果我检索到 +2(表示gmt + 2),如何将其转换为tzinfo对象?

I have no idea how to use datetime.tzinfo module. I have to convert a datetime data from UTC to local timezone and if I retrieve '+2'(which means gmt+2) how do I convert this to tzinfo object?

还可以在自动应用夏令时的情况下从UTC转换为本地时区吗?如何设置在dst期间仅自动减去一小时?

Also, is it possible to convert from UTC to local timezone with daylight saving time applied automatically? How do I set to subtract one hour automatically only during dst?

推荐答案

Python并不是真的实施良好的时区。根据文档,tzinfo只是一个抽象类,意味着

Python doesn't really implement well timezones. According to the documentation, tzinfo is just an abstract class meant to be implemented by the user.

我建议第三方用于处理时区的pytz 模块。

这篇关于如何在Python中使用datetime.tzinfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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