Proper conversion of timestamp

Ben Finney ben+python at
Wed Mar 5 03:33:47 CET 2014

Igor Korot <ikorot01 at> writes:

> On Tue, Mar 4, 2014 at 4:42 PM, MRAB <python at> wrote:
> >> But this particular question is easy.
> >>
> >> What I have is a timestamp which reads: 1289410678L.
> >>
> > That's an integer. It looks like the timestamp is a whole number of
> > seconds, so the number of milliseconds is 0. (I make it '2010-11-10
> > 17:37:58'.)
> Well it is this particular timestamp.

Which is what you presented as “what I have”.

> But I have a lot of files to process and some do have a timestamp with
> the milliseconds.

So, if you want help with such timestamps, you'll need to present a real
example (or preferably several exmaples) of timestamps that need this

> Right.
> The question is: how to get the number of milliseconds out of
> timestamp?

>From the timestamp you showed: The number of milliseconds is zero, since
it's an integer. That datatype will *always* have zero milliseconds.

> Once again: I can get the datetime object with the seconds precision
> by dividing it on 1000. But that will produce the datetime object with
> the seconds precision.

Because that's the data you're showing us: A timestamp with an integer
number of seconds.

> I can actually produce another timestamp with the milliseconds from a
> different file...

Then you won't be able to represent it as an integer number of seconds.
What are you receiving in the data? What data type is it?

 \      “He who allows oppression, shares the crime.” —Erasmus Darwin, |
  `\                                     grandfather of Charles Darwin |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list