使用 PowerShell 转换 Unix 时间 [英] Convert Unix time with PowerShell
本文介绍了使用 PowerShell 转换 Unix 时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PowerShell SQLite 模块解析 SQLite 数据库,以及一些返回值被创建和修改,都是在 Unix 时间.
I am parsing an SQLite database using the PowerShell SQLite module, and a couple of the return values are created and modified, both of which are in Unix time.
我想做的是以某种方式将其转换为人类时间".为了便于阅读,我删除了一些其他 SQL 查询.
What I would like to do is somehow convert that into "human time". I have removed some of the other SQL queries for ease of reading.
Import-Module SQLite
mount-sqlite -name GoogleDrive -dataSource E:Programming
ew.db
$cloud_entry = Get-ChildItem GoogleDrive:cloud_entry
foreach ($entry in $cloud_entry)
{
$entry.created
}
输出看起来像一大列 Unix 时间戳:
The output looks like a large column of Unix timestamps:
1337329458
更新:我最终选择了以下内容:
Update: I ultimately went with the following:
$ctime = $entry.created
[datetime]$origin = '1970-01-01 00:00:00'
$origin.AddSeconds($ctime)
推荐答案
参见 将 Unix 时间戳转换为 .NET DateTime.
您可以在 PowerShell 中轻松重现这一点.
You can easily reproduce this in PowerShell.
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$whatIWant = $origin.AddSeconds($unixTime)
这篇关于使用 PowerShell 转换 Unix 时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文