,你必須考慮到的主要空間和區域設置日期和時間格式。 (1)將日期和時間格式字符串臨時更改爲衆所周知的格式,(2)解析返回的%日期%和%時間%,適當處理空格,以及(3) )在LOGDATETIME變量中放置了一個完整的時間戳。
:logdatetime
reg copy "HKCU\Control Panel\International" "HKCU\Control Panel\International-Temp" /f >nul
reg add "HKCU\Control Panel\International" /v sShortDate /d "yyyy-MM-dd" /f >nul
set LogDate=%date%
reg add "HKCU\Control Panel\International" /v sTimeFormat /d "HH:mm:ss" /f >nul
set LogTime=%Time%
reg copy "HKCU\Control Panel\International-Temp" "HKCU\Control Panel\International" /f >nul
set loghour=%logtime:~0,2%
if "%loghour:~0,1%" == " " set loghour=0%loghour:~1,1%
set logmin=%logtime:~3,2%
if "%logmin:~0,1%" == " " set logmin=0%logmin:~1,1%
set logsec=%logtime:~6,2%
if "%logsec:~0,1%" == " " set logsec=0%logsec:~1,1%
set logyear=%logdate:~0,4%
set logmonth=%logdate:~5,2%
if "%logmonth:~0,1%" == " " set logmonth=0%logmonth:~1,1%
set logday=%logdate:~8,2%
if "%logday:~0,1%" == " " set day=0%day:~1,1%
set logdatetime=%logyear%%logmonth%%logday%%loghour%%logmin%%logsec%
goto :eof
使用它在你的代碼,只需在蝙蝠的開始調用它,並使用返回LOGDATETIME varialble
CALL :logdatetime
...
REN "D:\myfile.out" myfile-%LOGDATETIME%.out
感謝安迪,我最終使用: – Adam 2011-05-12 13:00:22
集FORMATTEDTIME =%時間: = - %和REN「MyFile.out」MyFile-%DATE:/ =% - %FormattedTime :: = %%。out它不會插入0,因此將它換成 - 。非常感謝您的幫助。亞當 – Adam 2011-05-12 13:03:06