批次:在%TIME%语法错误与环境变量 [英] Batch: syntax error on %time% with environment variables
本文介绍了批次:在%TIME%语法错误与环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上运行一个德国的Win7环境下可变的批处理脚本:
I'm running a Batch script on a German Win7 environment with the following variable:
%date%_%time:~0,2%-%time:~3,2%-%time:~6,2%
该脚本工作从10:00相当不错,直到23:59。 0:00之间9:59和我得到一个语法错误(我想因为时间有前只有一个数字:)
This script works quite well from 10:00 until 23:59. Between 0:00 and 9:59 i get a Syntax error (I suppose because the time has only one digit before the ":")
有人可以帮助我?
THX!
推荐答案
还有区域设置的依赖:
set "_datetime=%date%_%time:~0,2%-%time:~3,2%-%time:~6,2%"
set "_datetime=%_datetime: =0%"
有关的区域设置的独立解决方案(是的,没有 _
和 -
那时):
For locale independent solution (and yes, without _
and -
by then):
for /F "tokens=2 delims==" %%G in (
'wmic OS get LocalDateTime /value'
) do @for /F "tokens=*" %%x in ("%%G") do (
set "_datetime=%%~x"
)
set "_datetime=%_datetime:~0,14%"
goto :eof
下面的为
环路
-
%%摹
来检索LocalDateTime
值; -
%% X
删除结束的回车的在返回值(WMIC
行为:每个输出符合0x0D0D0A
结束,而不是常见的0x0D0A
)
%%G
to retrieve theLocalDateTime
value;%%x
to remove the ending carriage return in the value returned (wmic
behaviour: each output line ends with0x0D0D0A
instead of common0x0D0A
).
请参阅戴夫·贝纳姆的的 WMIC
和 FOR / F
:一个尾随修复< CR>
问题 的
See Dave Benham's WMIC
and FOR /F
: A fix for the trailing <CR>
problem
这篇关于批次:在%TIME%语法错误与环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文