我有一个如下所示的批处理脚本,它在我们的旧服务器(2008)中工作,但当我将它移动到新的时,它无法更新%d%:
rem @echo off
@set path=c:\test;%path%
@set d=%date:~-4,4%%date:~4,2%%date:~-7,2%
@set d=%d: =_%
@set t=%time:~0,2%%time:~3,2%%time:~6,2% @set t=%t: =0%
Rem Generate PGP encrypted file
@echo Starting PGP... >> c:\apps\ftpLogs\test.log
gpg2 --batch --yes -r testkey --output c:\test\foo\test_%d%.pgp --encrypt c:\test\foo\test_%d%.txt >> c:\apps\ftpLogs\test.log
当我将%d%更改为今天的日期时,pgp和每件事情都运行良好,但是在使用%d%的情况下,它会绕过这些行。任何帮助将不胜感激
答案 0 :(得分:2)
您在新服务器上禁用了扩展程序。尝试
@echo off
setlocal enableextensions
echo %date%
答案 1 :(得分:1)
我根据Working with Dates and Times using WMI以明确的日期格式开头。
@echo off
for /F "tokens=2* delims==" %%G in (
'wmic os get localdatetime/value'
) do @set "localdatetime=%%~G"
echo %localdatetime%
它应该显示与20150505222428.137000+120
相似的内容,这是以世界时间坐标(UTC)格式显示的日期。
在UTC格式中,日期显示为yyyymmddHHMMSS.xxxxxx±UUU
,其中:
yyyy represents the year.
mm represents the month.
dd represents the day.
HH represents the hour (in 24-hour format).
MM represents the minutes.
SS represents the seconds.
xxxxxx represents the milliseconds.
UUU represents the difference, in minutes, between
the local time zone and Greenwich Mean Time (GMT).
示例:
20150505222428.137000+120
yyyymmddHHMMSS.xxxxxx±UUU