批量打扰 - 需要2位数小时或抑制空间 [英] Batch bother - need 2 digit hour or suppressed space
问题描述
在'80'的回调中,我使用批处理脚本来记录SOAP注入
输出文件名是带时间戳的,但它只能在10:00之后正常工作!< br $>
In a thowback to the ''80''s I am using a batch script to log SOAP injections
The output file name is time stamped but it only works properly after 10:00!
echo on
echo %DATE%
echo %TIME%
set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetimef%
困难在于我找不到能够在小时或左边抑制空间的好例子用零填充它。
例如,''2013_03_06_ _8_16''将被表示为2013_03_06_08_16''或2013_03_06_8_16''
目前我得到''2013_03_06 __''
The difficulty is that I cannot find a good example that would suppress the space in the small hours or left pad it with zero.
e.g where ''2013_03_06_ _8_16'' would be represeted as either 2013_03_06_08_16'' or 2013_03_06_8_16''
Currently I get ''2013_03_06__''
推荐答案
你可以提取时间值的第一个字符,如果它是空间重建它带有前导零。像(我的.bat技能生锈):
You could extract the first character of the time value and if it''s a space rebuild it with a leading zero. Something like (my .bat skills being rusty):
set Z=%time:~0,1%
if %Z% NEQ 0 set Z=0
set newtime=%Z%%time:~1,7%
检查这个我意识到你需要检查数字1和2。
Reviewing this I realise you need to check for the digits 1 and 2 also.
这篇关于批量打扰 - 需要2位数小时或抑制空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!