2

I use connect the sqlite3 of chrome 'History' file for analysis. But there are data for last_visit_time, which is timestamp, but I don't know how to change it to real time. I test like this:

2012-04-18 23:22:11.084300 (utctime)

2012-04-19 01:22:11.084300 (myPC time)

12,979,264,931,952,304 (the time stamp in the data)

I printed the utctime and clicked a website, almost at the same time. So I get the statistic like above. 12,979,264,931,952,304 is the long int, so normal way to convert is not possible.

How can I convert the timestamp to a date?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Alex
  • 869
  • 3
  • 13
  • 20

1 Answers1

1

The timestamp it stores is the number of microseconds since midnight UTC on January 1st, 1601. To convert this to the current time, you can add the number of microseconds you have to the epoch date, with help from this answer, like this:

>>> import datetime
>>> epoch_start = datetime.datetime(1601, 1, 1)
>>> delta = datetime.timedelta(microseconds=12979264931952304)
>>> epoch_start + delta
datetime.datetime(2012, 4, 18, 23, 22, 11, 952304)

To convert to your local timezone, you can use this method (note that I am currently UTC - 4, while it looks like you are UTC + 2):

>>> from dateutil import tz
>>> from_zone = tz.tzutc()
>>> to_zone = tz.tzlocal()
>>> utc_time = (epoch_start + delta).replace(tzinfo=from_zone)
>>> utc_time.astimezone(to_zone)
datetime.datetime(2012, 4, 18, 19, 22, 11, 952304, tzinfo=tzlocal())
Community
  • 1
  • 1
jterrace
  • 64,866
  • 22
  • 157
  • 202