我正在尝试计算上次使用 CMD 重新启动计算机的时间。
但我不希望它采用年/月/日格式。
发送总天数、小时数和分钟数
这是我到目前为止所能做的:
setlocal
for /f "skip=1" %%i in ('wmic /node:Computer /USER / os get lastbootuptime') do (
set string=%%i
goto next
)
:next
echo Son Restart: %string:~6,2%/%string:~4,2%/%string:~0,4%---%string:~8,2%:%string:~10,2%
输出:儿子重启:17/11/2023---02:33
但我需要的是:2 天 - 8 小时 - 43 分钟
注意:我应该只使用 CMD,而不使用 powershell
非常感谢您提前的支持。
最佳答案
如果您乐意使用 WMIC,那么我可以提供替代方法吗:
@Echo Off
SetLocal EnableExtensions
Set "s="
For /F EOL^=S %%G In ('%SystemRoot%\System32\wbem\WMIC.exe Path
Win32_PerfFormattedData_PerfOS_System Get SystemUptime 2^>NUL
') Do Set /A s=%%G, d=s / 86400, s %%= 86400, h=s / 3600,^
s %%= 3600, m=s / 60, s=s %% 60 2>NUL
If Defined s (Echo %d% Days - %h% Hours - %m% Minutes
Pause)
EndLocal
Exit /B
当然,如果您也需要的话,您可以选择在输出中添加后缀 - %s% Seconds
。
关于batch-file - WMIC LastBootUptime 格式问题,需要的总天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77505194/