Python - calendar.timegm() vs. time.mktime()
Posted
by ibz
on Stack Overflow
See other posts from Stack Overflow
or by ibz
Published on 2010-06-02T10:42:53Z
Indexed on
2010/06/02
10:43 UTC
Read the original article
Hit count: 257
I seem to have a hard time getting my head around this.
What's the difference between calendar.timegm()
and time.mktime()
?
Say I have a datetime.datetime
with no tzinfo attached, shouldn't the two give the same output? Don't they both give the number of seconds between epoch and the date passed as a parameter? And since the date passed has no tzinfo, isn't that number of seconds the same?
>>> import calendar
>>> import time
>>> import datetime
>>> d = datetime.datetime(2010, 10, 10)
>>> calendar.timegm(d.timetuple())
1286668800
>>> time.mktime(d.timetuple())
1286640000.0
>>>
© Stack Overflow or respective owner