How to get UTC time in Python?

后端 未结 6 960
太阳男子
太阳男子 2020-12-02 10:47

I\'ve search a bunch on StackExchange for a solution but nothing does quite what I need. In JavaScript, I\'m using the following to calculate UTC time since Jan 1st 1970:

6条回答
  •  时光说笑
    2020-12-02 11:18

    Timezone aware with zero external dependencies:

    from datetime import datetime, timezone
    
    def utc_now():
        return datetime.utcnow().replace(tzinfo=timezone.utc)
    

提交回复
热议问题