windows下用时间戳创建文件名

英文环境下:

 

echo Archive_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.zip

中文:

  1. echo 根据当前日期时间,生成文件名称,......  
  2. set YYYYmmdd=%date:~0,4%%date:~5,2%%date:~8,2%  
  3. set hhmiss=%time:~0,2%%time:~3,2%%time:~6,2%  
  4. set "filename=WebSite3copy%YYYYmmdd%_%hhmiss%.zip"  
  5. echo %filename% 

去掉空格的方式:

  1. c:\>set h=%time:~0,2%
  2. c:\>set h=%h: =0%
  3. c:\>echo %date:~0,4%%date:~5,2%%date:~8,2%%h%%time:~3,2%%time:~6,2%
  4. 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 Files\MySQL\MySQL Server 5.6\bin

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.240\Infa_Shared\Mantis\%filename%

 

posted @ 2017-12-12 13:32  jaystarba  阅读(351)  评论(0编辑  收藏  举报