@echo off rem BAT获取系统日期,时间,并去掉时间小时前面的空格和时间后面的空格 echo *** %DATE% echo *** %TIME% set THISDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2% echo %THISDATE% rem 去掉小时前的空格 set h=%time:~0,2% set h=%h: =0% set log_filename=%date:~0,4%%date:~5,2%%date:~8,2%%h%%time:~3,2%%time:~6,2% rem 去掉左边边空格 rem :intercept_left rem if "%h:~0,1%"==" " set "h=%h:~1%"&goto intercept_left rem 去掉右边空格 :intercept_right if "%log_filename:~-1%"==" " set "log_filename=%log_filename:~0,-1%"&goto intercept_right echo %log_filename%.log pause
结果如下:
*** 2015/08/27 周四
*** 10:07:17.50
20150827
20150827100717.log