我在将存储浏览器历史记录的文件中的日期转换为正常日期时间时遇到了一些麻烦。
该文件位于: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/