标题: 求助 关于set /p
[打印本页]
作者: kcdsw
时间: 2006-5-31 11:14
标题: 求助 关于set /p
set /p
它的运算是不是不支持小数点?
另外
set a=09
set /p a=%a%+0
这样会提示错误 是bug么?
[
Last edited by kcdsw on 2006-5-31 at 12:18 ]
作者: bagpipe
时间: 2006-5-31 15:24
因此, 0x12 与 18 和 022
相同。请注意八进制公式可能很容易搞混: 08 和 09 是无效的数字,
因为 8 和 9 不是有效的八进制位数。
这不是BUG,而且LZ用/P好像不应该吧,那/A干什么用的,好好看看帮助在说吧
作者: bagpipe
时间: 2006-5-31 15:30
如果LZ就是需要这样做,那只能把变量a的数值设置成011或者010,011表示9,010表示8,八进制里是没有08 09 这两个数的,十进制的10,用八进制表示是012,楼主应该明白了吧!!!!!!!
作者: kcdsw
时间: 2006-5-31 19:32
呵呵 /p 是写错了
我明白了 当包含0前缀的时候 它会当作8进制来处理
[
Last edited by kcdsw on 2006-5-31 at 19:34 ]
作者: kcdsw
时间: 2006-5-31 19:55
set bt=%time%
ping 127.0.0.1 >nul 2>nul
set ot=%time%
::set bt=08:09:09.09
::set ot=09:09:09.09
set /a bt=1%bt:~0,2% * 360000 + 1%bt:~3,2% * 6000 + 1%bt:~6,2% * 100 + 1%bt:~9,2%
set /a ot=1%ot:~0,2% * 360000 + 1%ot:~3,2% * 6000 + 1%ot:~6,2% * 100 + 1%ot:~9,2%
if %ot% lss %bt% ( set /a ct=%ot% + 8640000 - %bt% ) else ( set /a ct=%ot% - %bt% )
echo %ct%毫秒
pause
主要是用来计算前后时间差的 不知道论坛有没有哪个高手写过
请指正
作者: willsort
时间: 2006-6-1 01:40
Re kcdsw:
此主题将被移动至批处理室。建议楼主修改主题的标题。
时间解析和运行的讨论本论坛曾经进行过[1],你也可以参考Ritchie Lawrence编写的Batch函数库[2],或者参考下面的示例代码[3]。
你的代码没有什么大的问题,只是为防止零前缀被set/a识别为八进制数,而将提取出的时间元素加前缀1,无法同时兼容处理类似8:09这样的不含前缀0的时间格式,尽管这种情形很合少出现。
另外,可以确定的是,set /a确实不支持浮点数运算。
[1] (已结)如果在WINDOWS下DOS命令行删除N天以前的文件
http://www.cn-dos.net/forum/viewthread.php?tid=16676
[2]Batch Function Library for Windows NT4/2000/XP/2003
http://www.commandline.co.uk/lib/treeview/index.php
[3]DateDiff.cmd
@echo off & setlocal ENABLEEXTENSIONS
set start=%1
set duration=%2
if "%2"=="" set start=2000/02/29-15:00 & set duration=36000
echo Start:%start%
echo Duration:%duration%
for /f "tokens=1-6 delims=/-:, " %%a in ('echo/%start%') do (
set sy=%%a & set sm=%%b & set sd=%%c
set sh=%%d & set sn=%%e & set ss=0
)
call :DateToSecs %sy% %sm% %sd% %sh% %sn% %ss% ssecs
set /a ssecs+=duration
call :SecsToDate %ssecs% ey em ed eh en es
echo/End:%ey%/%em%/%ed%-%eh%:%en%
goto :EOF
::::::::::::::::::::::::::::::-::::::::::::::::::::::::::::::-:::::::::::::::
:DateToSecs %yy% %mm% %dd% %hh% %nn% %ss% secs
::
:: By: Ritchie Lawrence, updated 2002-08-13. Version 1.1
::
:: Func: Returns number of seconds elapsed since 1st January 1970 00:00:00
:: UTC for a given calendar date and time of day. For NT4/2K/XP.
::
:: Args: %1 year to convert, 2 or 4 digit (by val)
:: %2 month to convert, 1/01 to 12, leading zero ok (by val)
:: %3 day of month to convert, 1/01 to 31, leading zero ok (by val)
:: %4 hours to convert, 1/01 to 12 for 12hr times (minutes must be
:: suffixed by 'a' or 'p', 0/00 to 23 for 24hr clock (by val)
:: %5 mins to convert, 00-59 only, suffixed by a/p if 12hr (by val)
:: %6 secs to convert, 0-59 or 00-59 (by val)
:: %7 var to receive number of elapsed seconds (by ref)
::::::::::::::::::::::::::::::-::::::::::::::::::::::::::::::-:::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5&set ss=%6
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,ss=100%ss%%%100
set /a j=j*86400+hh*3600+nn*60+ss
endlocal&set %7=%j%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SecsToDate %secs% yy mm dd hh nn ss
::
:: By: Ritchie Lawrence, updated 2002-07-24. Version 1.1
::
:: Func: Returns a calendar date and time of day from the number of
:: elapsed seconds since 1st January 1970 00:00:00 UTC. For NT4/2K/XP.
::
:: Args: %1 seconds used to create calendar date and time of day (by val)
:: %2 var to receive year, 4 digits for all typical dates (by ref)
:: %3 var to receive month, 2 digits, 01 to 12 (by ref)
:: %4 var to receive day of month, 2 digits, 01 to 31 (by ref)
:: %5 var to receive hours, 2 digits, 00 to 23 (by ref)
:: %6 var to receive minutes, 2 digits, 00 to 59 (by ref)
:: %7 var to receive seconds, 2 digits, 00 to 59 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set /a i=%1,ss=i%%60,i/=60,nn=i%%60,i/=60,hh=i%%24,dd=i/24,i/=24
set /a a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
(if %hh% LSS 10 set hh=0%hh%)&(if %nn% LSS 10 set nn=0%nn%)
if %ss% LSS 10 set ss=0%ss%
endlocal&set %7=%ss%&set %6=%nn%&set %5=%hh%&set %4=%dd%&set %3=%mm%&set %2=%yy%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[
Last edited by willsort on 2006-6-1 at 15:01 ]