0
我为编译“.net”代码的Jenkins作业编写了一个批处理脚本,其中一个步骤是在提取新的编译代码之前备份当前目录。如何在批处理脚本中将日期和时间插入文件名?
我使用这些行以提取我要插入到备份文件名的日期和时间:
for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set date=%%k%%i%%j
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do set time=%%a%%b
powershell.exe -nologo -noprofile -command "& { Add-Type -A System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::CreateFromDirectory('bin', 'bin-%date%_%time%.zip'); }"
xcopy bin-%date%_%time%.zip c:\temp
的问题是与time /t
的输出,看起来像这样:
01:00 AM
而导致的文件名是:
bin-20170412-0100 AM.zip
这是一个问题。
我想从时间变量中省略“AM”,该怎么办?
检查此问题 - http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us – npocmaka
谢谢,这就是我从中得到的线,但在我的情况下,从这篇文章中的例子返回给我的上午,并在他的答案,它似乎是不... –
这个想法是让时间独立于时间设置。 'date/t'和'time /'将在不同的机器上有所不同(顺便说一句,你可以使用'%date%'和'%time%variables') – npocmaka