c# - 将 Firefox 中 Places.sqlite 文件中的日期转换为 DateTime

标签 c# sqlite firefox datetime

我在将存储浏览器历史记录的文件中的日期转换为正常日期时间时遇到了一些麻烦。

该文件位于:C:\Users[username]\AppData\Roaming\Mozilla\Firefox\Profiles[profilename]\places.sqlite

有问题的表是:[moz_places]

该列是:[last_visit_date]

我试过使用 unix epoch 和 webkit 格式(如 chrome 使用),但都没有给我预期的结果。

这是我的 Unix 转换(不工作):

    public static DateTime FromUnixTime(long unixTime)
    {
        var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        return epoch.AddSeconds(unixTime);
    }

这是我的 webkit 转换代码:(也不适用于这些日期,它适用于 chromes webkit 日期)
    public static DateTime ConvertWebkitTimeToDateTime(long ticks)
    {
        //Set up a date at the traditional starting point for unix time.
        DateTime normalDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
        //Subtract the amount of seconds from 1601 to 1970.
        long convertedTime = (ticks - 11644473600000000);
        //Devide by 1000000 to convert the remaining time to seconds.
        convertedTime = convertedTime / 1000000;
        //Add the seconds we calculated above.
        normalDate = normalDate.AddSeconds(convertedTime);
        //Finally we have the date.
        return normalDate;
    }

那么 Firefox 存储的这些日期是怎么回事呢?这里有几个示例日期,它们都应该在今天或昨天左右。(大约 10/17/2013)

1373306583389000

1373306587125000

1373306700392000

任何帮助或文档链接都很棒,谢谢。

最佳答案

Unix 时间戳以秒为单位。
这些值大了一百万倍,即它们使用微秒:

> select datetime(1373306583389000 / 1000000, 'unixepoch');
2013-07-08 18:03:03

关于c# - 将 Firefox 中 Places.sqlite 文件中的日期转换为 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19429577/

相关文章:

c# - IntPtr 未在单声道中正确编码

c# - 在 .Net 标准项目中使用 Microsoft.AspNetCore.Identity?

objective-c - 确定 SQLite、CSV 或 Excel 中的架构字段类型

java - 将 TimePicker 数据保存在 sqlite 数据库中

html - 如何为不同的网络浏览器修复视频大小和字体换行

html - 网页内的 Firefox 打印选项

C# 4.0 MemoryCache - 如何在对其依赖项进行更改时逐出依赖缓存条目

c# - 使用字符串查找 C# 字典

c - sqlite3的共享库中可能存在内存泄漏

javascript - 在 Thunderbird 扩展中打开浏览器窗口