如何在批处理文件结果的开头添加时间戳?
这是我当前的代码:
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set tm=%time:~0,2%%time:~3,2%%time:~6,2%
ping www.google.com -t -l 1 >PingLog_%dt%-%tm%.txt
我希望结果与此类似:
[hh:mm:ss] Reply from 120.89.12.38: bytes=1 time=1ms TTL=59
最佳答案
添加格式的小编辑:
它在这里经过测试并且运行良好 - 尽管这台 PC 上的时间格式是 24 小时时间,这使其运行良好。
@echo off
setlocal enableDelayedExpansion
set dt=%date:~10,4%%date:~4,2%%date:~7,2%
set tm=%time:~0,2%%time:~3,2%%time:~6,2%
for /l %%# in (1,1,100) do (
set t=!time:~0,2!:!time:~3,2!:!time:~6,2!
for /f "tokens=* delims=" %%# in ('ping www.google.com -t -l 1 -n 1^|find /i "reply"') do (
echo [!t!] %%#
)
)
pause & goto :EOF
关于batch-file - 如何在批处理文件结果的开头添加时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35739609/