如何解析Chrome书签文件中的date_added字段?

时间:2013-09-29 04:32:41

标签: python google-chrome datetime

我看了

和互联网上的其他文章 但我无法理解如何将Chrome书签文件(Windows)中的date_added字段转换为合理的数字。

例如13024882639633631应该是2013年9月的日期,但我在我引用的第一个链接中尝试了所有可能的计算,但似乎无法获得明智的约会。它一直在计算日期为2010年。

3 个答案:

答案 0 :(得分:8)

我用chrome书签检查了它,它为所有人提供了正确的值。 13024882639633631似乎是昨天。点击此处https://code.google.com/p/chromium/codesearch#chromium/src/base/time/time_win.cc&sq=package:chromium&type=cs并搜索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')

答案 1 :(得分:5)

这只是将Zaw LIn的答案转换为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' ) )

输出:周六,2013年9月28日22:57:19

答案 2 :(得分:0)

与上述python脚本等效的javascript

function ConvertToDateTime(srcChromeBookmarkDate) {
    //Hp --> The base date which google chrome considers while adding bookmarks
    var baseDate = new Date(1601, 0, 1);

    //Hp --> Total number of seconds in a day.
    var totalSecondsPerDay = 86400;

    //Hp --> Read total number of days and seconds from source chrome bookmark date.
    var quotient = Math.floor(srcChromeBookmarkDate / 1000000);
    var totalNoOfDays = Math.floor(quotient / totalSecondsPerDay);
    var totalNoOfSeconds = quotient % totalSecondsPerDay;

    //Hp --> Add total number of days to base google chrome date.
    var targetDate =  new Date(baseDate.setDate(baseDate.getDate() + totalNoOfDays));

    //Hp --> Add total number of seconds to target date.
    return new Date(targetDate.setSeconds(targetDate.getSeconds() + totalNoOfSeconds));
}

var myDate = ConvertToDateTime(13236951113528894);
var alert(myDate);
//Thu Jun 18 2020 10:51:53 GMT+0100 (Irish Standard Time)