Portable general timestamp format, not 2038-limited
Peter J. Holzer
hjp-usenet2 at hjp.at
Wed Jul 4 23:18:10 CEST 2007
On 2007-07-04 18:46, James Harris <james.harris.1 at googlemail.com> wrote:
> On 1 Jul, 15:11, "Peter J. Holzer" <hjp-usen... at hjp.at> wrote:
>> Stick to unix timestamps but store them as a double precision floating
>> point number. The 53 bit mantissa gives you currently a resolution of
>> about 200 ns, slowly deteriorating (you will hit ms resolution in about
>> 280,000 years, if I haven't miscalculated). Any language and database
>> should be able to handle double-precision FP numbers, so that's as
>> portable as it gets and conversion from/to system time should be
>> If you need to represent milliseconds exactly, you can just multiply the
>> timestamp with 1000 (and get java timestamps).
> Interesting option. I think my choice is between separate day and sub-
> day 32-bit unsigned integers, text, and this 64-bit float option.
> I'm not clear, though. Did you mean to store double precision numbers
> where the seconds are the units (I assume this) or where the days are
> the units? And what do you think of the other option?
I was thinking about using the seconds as units (so
2007-07-04T23:02:04.123 CET is represented as 1183582924.123).
It's a natural extension of the unix time stamp, so you can often just
pass the values to the normal date routines (especially in languages
like perl which don't really distinguish between integers and floating
But it really doesn't matter much. If you ignore leap seconds, using
days instead of seconds is just a constant factor (in fact, the unix
timestamp ignores leap seconds, too, so it's always a constant factor).
You can't represent a second exactly if the unit is one day (1/86400 is
not a multiple of a power of two), but that probably doesn't matter.
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp at hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
More information about the Python-list