【问题标题】:Converting the date within the places.sqlite file in Firefox to a DateTime将 Firefox 中的 places.sqlite 文件中的日期转换为 DateTime
【发布时间】:2013-10-26 02:40:51
【问题描述】:

我在将存储浏览器历史记录的文件中的日期转换为正常的 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 存储的这些日期是怎么回事?这里有几个示例日期,应该都在今天或昨天。(大约 2013 年 10 月 17 日)

1373306583389000

1373306587125000

1373306700392000

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

【问题讨论】:

    标签: c# sqlite firefox datetime


    【解决方案1】:

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

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

    【讨论】:

    • 看起来不错,我找到了一个资源,展示了如何在 sql 函数本身中执行此操作,但我确实将其标记为 c# 问题。
    【解决方案2】:

    C# 中的解决方案:

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

    CL。是正确的,因为这只是 Unix 纪元的毫秒值。

    SQL 中的解决方案:

    这里有一个资源可以更详细地解释他的解决方案:

    https://support.mozilla.org/en-US/questions/835204

    【讨论】:

    • 这很好,但是由于整数除法,您在这里失去了一点精度。
    猜你喜欢
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 2015-07-09
    相关资源
    最近更新 更多