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

前端 未结 10 1230
失恋的感觉
失恋的感觉 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:52

    #First Example:
    from datetime import datetime, timezone    
    timstamp1 =int(datetime.now(tz=timezone.utc).timestamp() * 1000)
    print(timstamp1)
    

    Output: 1572878043380

    #second example:
    import time
    timstamp2 =int(time.time())
    print(timstamp2)
    

    Output: 1572878043

    • Here, we can see the first example gives more accurate time than second one.
    • Here I am using the first one.

提交回复
热议问题