Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

epoch - Convert Unix time with PowerShell

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.

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
}

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

See Convert a Unix timestamp to a .NET DateTime.

You can easily reproduce this in PowerShell.

$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$whatIWant = $origin.AddSeconds($unixTime)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...