Proper conversion of timestamp

MRAB python at
Wed Mar 5 05:11:05 CET 2014

On 2014-03-05 02:33, Ben Finney wrote:
> 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”.
I'd expect all of the timestamps to be the same type. That example is
an integer (a 'long' to be exact).

>> 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
> handling.
>> 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.
And in Python 2, an integer divided by an integer gives an integer.

>> 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?

More information about the Python-list mailing list