Python - simplest and most coherent way to get timezone-aware current time in UTC?

前端 未结 3 1065
清歌不尽
清歌不尽 2020-12-10 23:10

datetime.now() doesn\'t appear to have timezone info attached. I want the current time in UTC. What do I do?

>>> from datetime import         


        
3条回答
  •  离开以前
    2020-12-10 23:29

    I use pytz

    Then use the following bit of code

    import pytz
    from datetime import datetime
    now = datetime.utcnow().replace(tzinfo = pytz.utc)
    

提交回复
热议问题