What is the easiest way to get current GMT time in Unix timestamp format?

前端 未结 10 1236
失恋的感觉
失恋的感觉 2020-12-12 23:19

Python provides different packages (datetime, time, calendar) as can be seen here in order to deal with time. I made a big mistake by

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 23:49

    python2 and python3

    it is good to use time module

    import time
    int(time.time())
    

    1573708436

    you can also use datetime module, but when you use strftime('%s'), but strftime convert time to your local time!

    python2

    from datetime import datetime
    datetime.utcnow().strftime('%s')
    

    python3

    from datetime import datetime
    datetime.utcnow().timestamp()
    

提交回复
热议问题