windows命令行里取得年-月-日-时-分-秒的办法
FOR /f "tokens=*" %%G IN ('time/t') DO set _time=%%G
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%
echo %date:~0,4%-%date:~5,2%-%date:~8,2%-%_time%
执行后显示为:2009-02-17-09-15(样例)
windows命令行里取得年-月-日-时-分-秒,常用于数据库备份
如备份Oracle用户ZBFZ的数据并压缩(要求rar35.exe与bat文件在同一目录):
FOR /f "tokens=*" %%G IN ('time/t') DO set _time=%%G
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%
set _time=%date:~0,4%-%date:~5,2%-%date:~8,2%-%_time%
d:.\exp zfbz/zfbz@his owner=zfbz file=zfbz_%_time%.dmp log=zfbz_%_time%.log
rar35 a -df zfbz_%_time%.rar zfbz_%_time%.dmp zfbz_%_time%.log
备份过程最终生成zfbz__2009-02-17-09-15.rar文件。
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%
echo %date:~0,4%-%date:~5,2%-%date:~8,2%-%_time%
执行后显示为:2009-02-17-09-15(样例)
windows命令行里取得年-月-日-时-分-秒,常用于数据库备份
如备份Oracle用户ZBFZ的数据并压缩(要求rar35.exe与bat文件在同一目录):
FOR /f "tokens=*" %%G IN ('time/t') DO set _time=%%G
SET _time=%_time:~0,2%-%_time:~3,2%
ENDLOCAL&SET _time=%_time%
set _time=%date:~0,4%-%date:~5,2%-%date:~8,2%-%_time%
d:.\exp zfbz/zfbz@his owner=zfbz file=zfbz_%_time%.dmp log=zfbz_%_time%.log
rar35 a -df zfbz_%_time%.rar zfbz_%_time%.dmp zfbz_%_time%.log
备份过程最终生成zfbz__2009-02-17-09-15.rar文件。