2👍
✅
You are getting confused between local time (as returned by datetime.now()
and GMT (as parsed by calendar.timegm()
):
>>> t = datetime.now().strftime('%Y%m%dT%H%M%SZ')
>>> t
'20120910T232358Z'
>>> calendar.timegm(time.strptime(t, "%Y%m%dT%H%M%SZ"))
1347319438
>>> time.mktime(time.localtime())
1347312258.0
>>> time.mktime(time.strptime(t, "%Y%m%dT%H%M%SZ"))
1347312238.0
Conclusion: use time.mktime
instead of calendar.timegm
to turn your values to timestamps.
Source:stackexchange.com