echo %date:~0,4%%date:~5,2%%date:~8,2%
输出:20170315
echo %date:~0,4%-%date:~5,2%-%date:~8,2%
输出:2017-03-15
对小时,不够两位需要格式化
@echo off
set hour=%time:~,2%
if "%time:~,1%"==" " set hour=0%time:~1,1%
echo %date:~0,4%%date:~5,2%%date:~8,2%%hour%%time:~3,2%%time:~6,2%
pause