need to print seconds from the epoch including the millisecond

Grant Edwards invalid at invalid.invalid
Thu Jan 2 11:23:22 EST 2014


On 2013-12-26, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> matt.doolittle33 at gmail.com wrote:
>
>> On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
>>> On Thu, Dec 26, 2013 at 10:32 AM,  <matt.doolittle33 at gmail.com> wrote:
>>> 
>>> > i am using 2.7.   I need to print the time in seconds from the epoch
>>> > with millisecond precision.  i have tried many things but have failed. 
> [...]
>>> In [1]: import time
>>> In [2]: time.time()
>>> Out[2]: 1388085670.1567955
>>
>> 
>> OK i did what you said but I am only getting 2 decimal places.
>> Why is this and what can I do to get the millisecond?
>
> Please show *exactly* what you did. Also please tell us what operating
> system you are using. It may be that your operating system's clock doesn't
> provide millisecond precision.

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.

-- 
Grant Edwards               grant.b.edwards        Yow! Will the third world
                                  at               war keep "Bosom Buddies"
                              gmail.com            off the air?



More information about the Python-list mailing list