2019/06/26

How to generate date and time log in Windows batch script


for /f "skip=1 delims=" %%z in ('wmic os get localdatetime') do if not defined Z set Z=%%z
set DATE=%Z:~0,4%-%Z:~4,2%-%Z:~6,2%
set TIME=%Z:~8,2%-%Z:~10,2%-%Z:~12,2%
set timestamp=%DATE%_%TIME%.log

or

set timestamp=%DATE:/=-%@%TIME::=-%
set timestamp=%timestamp: =%
set timestamp=%timestamp:,=.%.log

or

set timestamp=%date:~0,4%%date:~5,2%%date:~8,2%@%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
set timestamp=%timestamp:,=.%.log

沒有留言:

張貼留言