1. 程式人生 > >windows下用時間戳創建文件名

windows下用時間戳創建文件名

str sym start ebs mbo tracker tail class mysql\

英文環境下:

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%

windows下用時間戳創建文件名