使用PowerShell转换Unix时间 [英] Convert Unix time with PowerShell

查看:122
本文介绍了使用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\new.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆