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\new.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)
[datetime] '1970-01-01 00:00:00'creates a[datetime]instance whose.Kindproperty isUnspecified. By contrast, the start of Unix epoch time is unambiguously UTC.[datetime] '1970-01-01Z', which gives you aLocal[datetime]instance; if you need aUtcinstance, use([datetime] '1970-01-01Z').ToUniversalTime()Utc[datetime]instance, add the Unix epoch time (in seconds) to it, and then convert to local time:([datetime] '1970-01-01Z').ToUniversalTime().AddSeconds($ctime).ToLocalTime(). Alternatively, using[datetimeoffset](which is preferable in general):[datetimeoffset] '1970-01-01Z').AddSeconds($ctime).LocalDateTime