英文:
Powershell Add a value with current time to get calculated time
问题
我想要将天、小时或分钟添加到当前时间以获取我的计算时间。到目前为止,我正在使用以下代码,它正在工作,但是否有改进的方法?
$ts = New-TimeSpan -Days 0 -Hours 8 -Minutes 40
$ot = (Get-Date).Add($ts)
$ft = (Get-Date $ot).ToString('hh:mm')
上面的代码可以给您一个计算的时间,但我们可以将其简化成一行吗?
英文:
I want to add days or hours or minutes to the current time get my calculated time . As of now I'm using below code , it is working but is there any way we could improve
$ts = New-TimeSpan -Days 0 -Hours 8 -Minutes 40
$ot = (get-date) + $ts
$ft = get-date $ot -Format hh:mm
Above code can give you a calculated time but can we make it into a single line ?
答案1
得分: 0
你可以将所有这些组合成一行代码:
$ft = (Get-Date) + (New-TimeSpan -Days 0 -Hours 8 -Minutes 40) | Get-Date -Format hh:mm
英文:
You can combine all of that into a single line as
$ft = (Get-Date) + (New-TimeSpan -Days 0 -Hours 8 -Minutes 40) | Get-Date -Format hh:mm
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论