need to print seconds from the epoch including the millisecond

Grant Edwards invalid at invalid.invalid
Fri Jan 3 10:33:18 EST 2014


On 2014-01-03, Dave Angel <davea at davea.name> wrote:
> On Thu, 2 Jan 2014 16:23:22 +0000 (UTC), Grant Edwards 
><invalid at invalid.invalid> wrote:
>> AFAIK, that's irrelevent.  time.time() returns a float.  On all the
>> CPython implementations I know of, that is a 64-bit IEEE format, 
>> which provides 16 decimal digits of precision regardless of the 
>> granularity of the system time value.  At this point in time, that
>> means 10 digits left of the decimal point and 6 to the right.
>
> Correction: no more than about 6 to the right.  You can certainly get 
> less, from an os with a smaller resolution.

time.time() returns a Python float. A Python float will have 16 digits
of precision. Perhaps the OS always sets some of those digits to 0 (or
even random values), but they're still there.  Perhaps the accuracy or
granularity of the values returned is problematic on some OSes, but
the precision of the value doesn't change: there's no way he's "only
getting 2 decimal places" from time.time() unless (as you mention
below) he's printing them using a method that truncates/rounds.

> Or you can lose some of what you do get by printing in a sub-optimal
> way.

Yes, depending on how you print the value, you can hide some of the
digits.  But, there's no way for time.time() to return a value with
less than ~16 decimal digits of precicsion.

-- 
Grant Edwards               grant.b.edwards        Yow! !  Everybody out of
                                  at               the GENETIC POOL!
                              gmail.com            



More information about the Python-list mailing list