Message76340
| Author |
vstinner |
| Recipients |
Neil Muller, andersjm, belopolsky, davidfraser, hodgestar, tebeka, vstinner, werneck |
| Date |
2008年11月24日.17:13:41 |
| SpamBayes Score |
1.7421414e-07 |
| Marked as misclassified |
No |
| Message-id |
<1227546823.91.0.931359618478.issue2736@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|