CODE: [Copy to clipboard]
@echo off
echo set time=%%3>current.bat
rem 将文本set time=%3输出到current.bat中,准备作为命令调用。
echo.|time>setclock.bat
rem 将当前时间信息输出到setclock.bat中
rem echo.输出一个结束time需要的回车符,由管道符号"|"传给time
rem setclock的文本内容第一行类似于 Current time is 22:00:02.41
rem 也准备作为命令调用,第二行执行不到可以不用管
call setclock.bat
rem 调用setclock后返回(因为有Call)
rem setclock的执行中再调用current.bat而不返回(因为没有Call),所以第二行被跳过
rem 而time is 22:00:02.41 则成为了current执行时的命令行参数
rem 而current.bat的 set time=%3 意为将第三个参数赋给变量time,正是22:00:02.41
rem 将程序命令输出的文本信息作为再次作为程序命令执行,是这个批处理用到的最大的技巧。此技巧可以用于完成很多相当复杂批处理控制
rem 以下是日期变量的获取,与时间变量类似,不用赘述。
echo set week=%%3>current.bat
echo set date=%%4>>current.bat
echo.|date>setclock.bat
call setclock.bat
del current.bat
del setclock.bat
另外,请注意,我的ID是willsort,而非WILLSOFT,我的职业与软件销售毫无关联。