How to check if a datetime object is localized with pytz?

前端 未结 4 860
你的背包
你的背包 2020-12-05 03:42

I want to store a datetime object with a localized UTC timezone. The method that stores the datetime object can be given a non-localized datetime (naive) object or an object

4条回答
  •  时光说笑
    2020-12-05 04:35

    Here is a function wrapping up the top answer.

    def tz_aware(dt):
        return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
    

提交回复
热议问题