Python 如何解析Chrome书签文件中添加的日期字段?
我看过Python 如何解析Chrome书签文件中添加的日期字段?,python,google-chrome,datetime,Python,Google Chrome,Datetime,我看过 以及互联网上大量的其他文章 但我一辈子都无法理解如何将Chrome书签文件(Windows)中添加的日期字段转换为合理的数字 例如,13024882639633631应该是2013年9月的一个日期,但我在我引用的第一个链接中尝试了所有可能的计算,但似乎找不到合理的日期。它一直在计算2010年的日期。我用chrome书签检查了它,它给出了所有的正确值13024882639633631似乎是昨天。检查此处并搜索MicrosecondsToFileTime import dateti
例如,
13024882639633631
应该是2013年9月的一个日期,但我在我引用的第一个链接中尝试了所有可能的计算,但似乎找不到合理的日期。它一直在计算2010年的日期。我用chrome书签检查了它,它给出了所有的正确值<代码>13024882639633631似乎是昨天。检查此处并搜索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的答案转换为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' ) )
输出:Sat,2013年9月28日22:57:19上述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年1月1日午夜UTC起的秒。Chrome time.h明确表示它基于Windows epoch 1601-01-01 00:00:00 UTC。不是Unix历元或常规*nix时间戳。