Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse the date_added field in Chrome Bookmarks file?

I've looked at

  • Google Bookmark Export date format?
  • http://productforums.google.com/forum/#!topic/chrome/-ujeAr1_YFQ
  • convert 64 bit windows date time in python

and loads of other articles on the internet but I cannot for the life of me understand how to convert the date_added field in the Chrome Bookmarks files (Windows) to a sensible number.

For instance 13024882639633631 is supposed to be a date in September 2013 but I tried all possible calculations in the 1st link I cited but can't seem to get a sensible date. It keeps calculating the date as 2010.

like image 461
keithxm23 Avatar asked Sep 29 '13 04:09

keithxm23


2 Answers

i have checked it with chrome bookmarks and it gave correct values for all. 13024882639633631 appears to be yesterday. check here https://code.google.com/p/chromium/codesearch#chromium/src/base/time/time_win.cc&sq=package:chromium&type=cs and search for MicrosecondsToFileTime

import datetime

def getFiletime(dt):
    microseconds = int(dt, 16) / 10
    seconds, microseconds = divmod(microseconds, 1000000)
    days, seconds = divmod(seconds, 86400)

    return datetime.datetime(1601, 1, 1) + datetime.timedelta(days, seconds, microseconds)

print format(getFiletime(hex(13024882639633631*10)[2:17]), '%a, %d %B %Y %H:%M:%S %Z')
like image 95
Zaw Lin Avatar answered Oct 28 '22 14:10

Zaw Lin


This is just a conversion of the answer by Zaw LIn to python 3.

import datetime

def getFiletime(dtms):
  seconds, micros = divmod(dtms, 1000000)
  days, seconds = divmod(seconds, 86400)

  return datetime.datetime(1601, 1, 1) + datetime.timedelta(days, seconds, micros)

print( getFiletime(13024882639633631).strftime( '%a, %d %B %Y %H:%M:%S %Z' ) )

Output: Sat, 28 September 2013 22:57:19

like image 43
Randy Skretka Avatar answered Oct 28 '22 14:10

Randy Skretka