batch-file - 如何在批处理文件结果的开头添加时间戳

标签 batch-file timestamp ping

如何在批处理文件结果的开头添加时间戳?

这是我当前的代码:

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/

相关文章:

c++ - 回复 Ping 广播

linux - 为什么CapEff在/proc/$PID/status中全为零

android - 使用 google play 服务自动将 android apk 推送到 google play

java - 获取java类的编译时间戳

node.js - "npm config set registry https://registry.npmjs.org/"在 windows bat 文件中不工作

mysql - rails 4 : how to use UNIX_TIMESTAMP with group YEAR

PostgreSQL:选择时间戳字段上的数据

vb.net - 检查FTP是否在线/离线

string - 批量 * 通配符替换

windows - 为什么这个 FOR 命令不删除除我想保留的文件以外的所有文件?