[Tutor] Timestamp issues when importing from FireFox sqlite field

Peter Otten __peter__ at web.de
Thu Jul 18 20:23:47 CEST 2013


Paul Smith wrote:

> Attempting timestamp translation via python importing info from sqlite
> datetime item in firefox ,'1369751000393000'. Typical unix date time
> translation fails. I noted micro second addition but even
> '1369751000393000' / 1e6 does not get a chew-able range, at least in
> python datetime module. Any suggestions?


> 
datetime.datetime.fromtimestamp(int("1369751000393000/1e6")).strftime('%Y-%m-%d
> %H:%M:%S')
> ValueError: invalid literal for int() with base 10: '1369751000393000/1e6'

The problem is not with the timestamp or the datetime module. You are 
attempting the division inside the string. Wrong:

>>> int("1369751000393000/1e6")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1369751000393000/1e6'

Correct:

>>> int("1369751000393000")/1e6
1369751000.393
>>> import datetime
>>> datetime.datetime.fromtimestamp(int("1369751000393000")/1e6)
datetime.datetime(2013, 5, 28, 16, 23, 20, 393000)
>>> 
datetime.datetime.fromtimestamp(int("1369751000393000")/1e6).strftime("%c")
'Tue May 28 16:23:20 2013'




More information about the Tutor mailing list