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

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

    Or just simply using the datetime standard module

    In [2]: from datetime import timezone, datetime
       ...: int(datetime.now(tz=timezone.utc).timestamp() * 1000)
       ...: 
    Out[2]: 1514901741720
    

    You can truncate or multiply depending on the resolution you want. This example is outputting millis.

    If you want a proper Unix timestamp (in seconds) remove the * 1000

提交回复
热议问题