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

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


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

import timetime.time()

Output:

1369550494.884832

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


import timeint(time.time()) 

Output:

1521462189


Does this help?

from datetime import datetimeimport calendard = datetime.utcnow()unixtime = calendar.timegm(d.utctimetuple())print unixtime

How to convert Python UTC datetime object to UNIX timestamp