0

I scraped chrome history using python. late_visit_time row is giving a timestamp, something like this - 13107300761977770. When I converted it to date using following code:

timestamp = 13107300761977770
value = datetime.datetime.fromtimestamp(timestamp)

I got following error:

Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
value = datetime.datetime.fromtimestamp(timestamp)
OSError: [Errno 22] Invalid argument

I even changed my code to this:

timestamp = 13107300761977770/1e3
value = datetime.datetime.fromtimestamp(timestamp)

but I got the same error.

After that, to change timestamp's size to I did this:

timestamp = 13107300761977770/1e7
value = datetime.datetime.fromtimestamp(timestamp)
print(value)

It gave me 2011-07-15 17:11:16.197777 as a result which was wrong because the history which I used as my sample data was collected in 2016 only.
What should be the possible solution to my problem?

jfs
  • 399,953
  • 195
  • 994
  • 1,670
Shuvam Shah
  • 357
  • 2
  • 6
  • 13

1 Answers1

1
import datetime

timestamp = 13107300761977770
value = datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=timestamp)
print(value)
afquintana
  • 26
  • 2