格式化PowerShell时间输出

时间:2013-04-30 14:16:00

标签: powershell dos

我有一个像这样的PowerShell脚本:

$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,StartTime,@{l="Owner";e={$owners[$_.id.tostring()]}}

我想将StartTime格式化为24h格式并且不显示秒数。我该怎么做?

1 个答案:

答案 0 :(得分:2)

试试这个:

$owners = @{}
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
get-process | select processname,Id,@{l="StartTime";e={ get-date $($_.starttime) -f "dd/MM/yy HH.mm" }},@{l="Owner";e={$owners[$_.id.tostring()]}}