1
Import-Module SQLite
mount-sqlite -name places -data (resolve-path C:\Users\malware_win7x86\Desktop\places.sqlite)
$places = Get-ChildItem places:\moz_places

foreach ($entry in $places)
{
    [datetime]$origin = '1970-01-01 00:00:00'
    $visited = $entry.last_visit_date

    if ($visited) {
        $vtime = $origin.AddSeconds($visited)
    } else {
        $vtime = 'testing'
    }

    write-host ""
    $entry.url,
    $entry.visit_count,
    $vtime
}

参考:使用 PowerShell 转换 Unix 时间

我很好奇如何处理没有数据的条目。

例如,以下是该脚本的一些输出:

http://sysforensics.org/
1
Exception calling "AddSeconds" with "1" argument(s): "Value to add was out of range.
Parameter name: value"
At line:7 char:28
+ $vtime = $origin.AddSeconds <<<< ($visited)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

对此有什么想法吗?

谢谢

4

2 回答 2

2

该错误看起来像是您给出AddSeconds的参数太大或太小,而不是缺少数据。AddSeconds使用$null或调用0将返回原始日期不变。

话虽这么说——我不能确定,因为你没有提供你想要转换的实际整数——我遇到了同样的问题,直到我意识到我收到的数据是以毫秒为单位的,而不是秒. 如果您不关心精度的损失,您可以使用AddMilliseconds,或者在使用前将数字除以 1000 。AddSeconds

感谢这个答案为我指明了正确的方向。

于 2015-04-27T18:46:25.867 回答
0

在这种情况下,您只需跳过方法调用并替换默认值,例如:

if ($visited) { # or maybe $ivisited -is [int] or whatever your criterion is
  $vtime = $origin.AddSeconds($visited)
} else {
  $vtime = $null
}
于 2012-07-26T11:36:51.353 回答