mrw*_*1t3 7 powershell epoch unix-timestamp
我正在使用PowerShell SQLite模块解析SQLite数据库,并创建和修改了几个返回值,这两个值都在Unix时间.
我想做的是以某种方式将其转换为"人类时间".为了便于阅读,我删除了一些其他SQL查询.
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
}
Run Code Online (Sandbox Code Playgroud)
我选择了以下内容:
1337329458
Run Code Online (Sandbox Code Playgroud)
输出看起来像一大堆Unix时间戳:
$ctime = $entry.created
[datetime]$origin = '1970-01-01 00:00:00'
$origin.AddSeconds($ctime)
Run Code Online (Sandbox Code Playgroud)
Joh*_*hnB 21
您可以在PowerShell中轻松重现此内容.
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$whatIWant = $origin.AddSeconds($unixTime)
Run Code Online (Sandbox Code Playgroud)
ukn*_*guy 15
Function Convert-FromUnixDate ($UnixDate) {
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixDate))
}
$niceTime = Convert-FromUnixDate $ctime
PS C:\> $niceTime
Friday, 18 May 2012 8:24:18 p.m.
Run Code Online (Sandbox Code Playgroud)
用:
(([System.DateTimeOffset]::FromUnixTimeSeconds($unixTime)).DateTime).ToString("s")
Run Code Online (Sandbox Code Playgroud)
FromUnixTimeMilliseconds 也可用。
ToString("s"): Sortable: "该模式反映了定义的标准 (ISO 8601)"
小智 7
$date = get-date "1/1/1970"
$date.AddSeconds($unixTime).ToLocalTime()
Run Code Online (Sandbox Code Playgroud)
一个简单的单线:
(Get-Date "1970-01-01 00:00:00.000Z") + ([TimeSpan]::FromSeconds($unixTime))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36313 次 |
| 最近记录: |