[issue2736] datetime needs and "epoch" method

Miki Tebeka report at bugs.python.org
Thu May 1 23:03:29 CEST 2008


New submission from Miki Tebeka <miki.tebeka at gmail.com>:

If you try to convert datetime objects to seconds since epoch and back
it will not work since the microseconds get lost:

>>> dt = datetime(2008, 5, 1, 13, 35, 41, 567777)
>>> seconds = mktime(dt.timetuple())
>>> datetime.fromtimestamp(seconds) == dt
False

Current fix is to do
>>> seconds += (dt.microsecond / 1000000.0)
>>> datetime.fromtimestamp(seconds) == dt
True

----------
components: Library (Lib)
messages: 66045
nosy: tebeka
severity: normal
status: open
title: datetime needs and "epoch" method
type: behavior
versions: Python 2.6, Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2736>
__________________________________


More information about the Python-bugs-list mailing list