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

Cory picture Cory · May 26, 2013 · Viewed 264.4k times · Source

Python provides different packages (datetime, time, calendar) as can be seen here in order to deal with time. I made a big mistake by using the following to get current GMT time time.mktime(datetime.datetime.utcnow().timetuple())

What is a simple way to get current GMT time in Unix timestamp?

Answer

Edmond Burnett picture Edmond Burnett · May 26, 2013

I would use time.time() to get a timestamp in seconds since the epoch.

import time

time.time()

Output:

1369550494.884832

For the standard CPython implementation on most platforms this will return a UTC value.