powershell - PowerShell New-TimeSpan 以天(s)小时(s)分钟(s)秒显示友好
问题描述
我一直在寻找类似于.NET 示例中的示例的 PowerShell 脚本。取一个 New-TimeSpan 并显示为 1 天 2 小时 3 分钟 4 秒。排除它的零,在需要的地方添加复数“s”。有谁有这个好用的吗?
据我所知:
$StartDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt")
Write-Host "Start Time: $StartDate"
# Do Something
$EndDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt")
Write-Host "End Time: $EndDate" -ForegroundColor Cyan
$Duration = New-TimeSpan -Start $StartDate -End $EndDate
$d = $Duration.Days; $h = $Duration.Hours; $m = $Duration.Minutes; $s = $Duration.Seconds
Write-Host "Duration: $d Days, $h Hours, $m Minutes, $s Seconds"
解决方案
表格视图还不错:
new-timespan -Days 1 -Hours 1 -Minutes 1 -Seconds 1 | ft
Days Hours Minutes Seconds Milliseconds
---- ----- ------- ------- ------------
1 1 1 1 0
推荐阅读
- reactjs - 过滤数组数据并返回
- apache - 重写 .htaccess 中的 URL 以用正斜杠 (id?=value) 替换查询参数
- javascript - 为什么我的状态没有在 setInterval 和 useEffect 的函数内部重置
- javascript - 从服务器获取 rowData 时使用 valueGetter 的 Ag-grid React 列移动
- angular - 角度 12 顶点烛台折线图工具提示错误
- php - PhpStorm 和 Xdebug 配置
- java - 将 UTC 时间戳转换为用户时区
- node.js - Heroku 图像在新的推送中消失了
- html - 如何为上角的上传图像添加删除图标
- python - 用文件夹内每个文件中的空格替换句点和逗号,然后打印文件