How to properly get the microseconds from the timestamps?

Vlastimil Brom vlastimil.brom at gmail.com
Tue Apr 22 05:15:17 EDT 2014


2014-04-22 4:38 GMT+02:00 Igor Korot <ikorot01 at gmail.com>:
...
>>>> datetime.datetime.fromtimestamp(1092787200/1000.0)
> datetime.datetime(1970, 1, 13, 7, 33, 7, 200000)
>
> Is there a way to know if the timestamp has a microseconds?
>
> Thank you.
> --
Hi,
I believe, in these cases, you can just test, whether there is a
non-integer part in the timestamp in seconds, which will be stored as
microseconds accordingly.
>>> 1092787200/1000.0
1092787.2
0.2 s is stored (and shown in repr(...)) as  200000  microseconds.

There are some peculiarities in handling date and time calculations
reliably as well as in the floating point math, but they don't seem to
be involved here.



More information about the Python-list mailing list