我用%date:~10%%date:~7,2%%date:~4,2%%time:~0,2%%time:~3,2%
表示日期
输出应如下所示: 201706161102
但输出:016.1102
怎么了?
我建议您使用 WMIC
命令的输出,如下所示:
@echo off
Title Get Date and Time with WMIC
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
echo YYYYMMDDHHMinSec
Set "DateTimeVar=%YYYY%%MM%%DD%%HH%%Min%%Sec%"
echo %DateTimeVar%
pause