【问题标题】:How to parse the date_added field in Chrome Bookmarks file?如何解析 Chrome 书签文件中的 date_added 字段?
【发布时间】:2013-09-29 04:32:40
【问题描述】:

我看过

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

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

【问题讨论】:

    标签: python google-chrome datetime


    【解决方案1】:

    我已使用 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')
    

    【讨论】:

    • 感谢 Zaw Lin,这太完美了!很抱歉,我在我写 12 月而不是 9 月的问题中犯了一个错误。无论如何,我在几个示例上运行了代码,效果很好!我应该考虑查看 Chromium 源。非常感谢 Zaw Lin!
    • 这是基于Unix epoch time,但以微秒(即百万分之一秒)为单位,而不是自 1970 年 1 月 1 日午夜 UTC 以来的秒数。
    • Chrome time.h 明确告诉它基于 Windows epoch 1601-01-01 00:00:00 UTC。不是 Unix 纪元或常规 *nix 时间戳。
    【解决方案2】:

    这只是 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

    【讨论】:

      【解决方案3】:

      上述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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-07
        • 1970-01-01
        • 1970-01-01
        • 2020-01-02
        • 2015-06-29
        • 2018-07-13
        • 2023-03-17
        相关资源
        最近更新 更多