批次檔範例如下
for /L %%I in (0 1 430) do (
echo %DATE% %TIME%
echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%
timeout /t 30
)
原本的本意是想取得當下的系統時間
但是執行後才發現,顯示出來的時間一直停留在剛執行批次檔的時間
請問有人可以幫忙解惑嗎?
請參考
@Echo off
SetLocal ENABLEDELAYEDEXPANSION
for /L %%I in (0 1 430) do (
echo !DATE! !TIME!
echo !date:~0,4!-!date:~5,2!-!date:~8,2! !time:~0,2!:!time:~3,2!
timeout /t 30
)
請試以下批次檔內容~
@echo off
for /L %%I in (0 1 430) do (
@call :GetDateTime %%I
timeout /t 30
)
:ExitBat
goto :EOF
:GetDateTime
echo I=(%1)
echo %DATE% %TIME%
echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%
goto :EOF
:Function_date
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set yy=%%a& set mm=%%b& set dd=%%c& set ww=%%d)
set mmm=1%mm% & set /a mmm-=100
set ddd=1%mm% & set /a ddd-=100
set /a today_cnt=(%yy%-%YearStart%)*365+%mmm%*30+%ddd%
:Function_date_end
:Function_time
for /f "tokens=2-5 delims=:. " %%a in ('echo. ^|time') do (set hhh=%%a& set min=%%b& set sec=%%c& set cent=%%d)
if %hhh% LSS 10 (set hhh=0%hhh%)
:Function_time_end
set Destination=_%yy%_%mm%%dd%_%hhh%%min%_%sec%%cent%
D:\>set Destination=_2016_1211_1544_5047