英文环境下:
echo Archive_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.zip
中文:
- echo 根据当前日期时间,生成文件名称,......
- set YYYYmmdd=%date:~0,4%%date:~5,2%%date:~8,2%
- set hhmiss=%time:~0,2%%time:~3,2%%time:~6,2%
- set "filename=WebSite3copy%YYYYmmdd%_%hhmiss%.zip"
- echo %filename%
去掉空格的方式:
- c:>set h=%time:~0,2%
- c:>set h=%h: =0%
- c:>echo %date:~0,4%%date:~5,2%%date:~8,2%%h%%time:~3,2%%time:~6,2%
- 20150324090254
参考的链接: http://blog.csdn.net/chinadm123/article/details/44588891
http://blog.csdn.net/xuexiaodong009/article/details/53462592
https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name
我的备份mantis的脚本:
cd C:Program FilesMySQLMySQL Server 5.6in
set h=%time:~0,2%
set h=%h: =0%
set "filename=Mantis_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql"
echo %filename%
mysqldump -uroot -p3edc$RFV bugtracker > \172.16.10.240Infa_SharedMantis\%filename%