[issue2736] datetime needs and "epoch" method
STINNER Victor
report at bugs.python.org
Mon Nov 24 18:13:43 CET 2008
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
Ooops, timestamp (c) is the *Mac* timestamp: seconds since the 1st
january 1904.
> what is your conclusion?
Hum, it's maybe not possible to choose between integer and float. Why
not supporting both? Example:
- totimestamp()->int: truncate microseconds
- totimestamp(microseconds=True)->float: with microseconds
Attached file (timestamp.py) is a module to import/export timestamp in
all listed timestamp formats. It's written in pure Python.
----------------
>>> import timestamp
>>> from datetime import datetime
>>> now = datetime.now()
>>> now
datetime.datetime(2008, 11, 24, 18, 7, 50, 216762)
>>> timestamp.exportUnix(now)
1227550070
>>> timestamp.exportUnix(now, True)
1227550070.2167621
>>> timestamp.exportMac(now)
3310394870L
>>> timestamp.exportWin64(now)
128720236702167620L
>>> timestamp.exportUUID(now)
134468428702167620L
>>> timestamp.importMac(3310394870)
datetime.datetime(2008, 11, 24, 18, 7, 50)
>>> timestamp.importUnix(1227550070)
datetime.datetime(2008, 11, 24, 18, 7, 50)
>>> timestamp.importUnix(1227550070.2167621)
datetime.datetime(2008, 11, 24, 18, 7, 50, 216762)
----------------
It supports int and float types for import and export.
Added file: http://bugs.python.org/file12123/timestamp.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue2736>
_______________________________________
More information about the Python-bugs-list
mailing list