0

两者都不

@echo off

set hh=!tm:~0,2
set mm=!tm:~3,2
set ss=!tm:~5,2
set ms=!tm:~7,2

if !hh! gtr **5** (
    echo gtr 5
    pause
    goto success
)


pause
goto fail

:success
echo Success!
pause
exit

:fail
echo Fail!
pause
exit

或者

@echo off

set hh=!tm:~0,2
set mm=!tm:~3,2
set ss=!tm:~5,2
set ms=!tm:~7,2

if !hh! gtr **05** (
    echo gtr 5
    pause
    goto success
)


pause
goto fail

:success
echo Success!
pause
exit

:fail
echo Fail!
pause
exit

按我的需要工作

这应该让它在上午 10 点输出大于上午 5 点。即使是上午 10 点,它也只说不到 5 点。最重要的是,如果我将时间设置为凌晨 5 点,它仍然会说它小于凌晨 5 点且不等于凌晨 5 点。

它仅适用于单个数字的任何时间,例如 0-9(即上午 12 点至上午 9 点)。任何时候都是两位数,所以 10-23(上午 10 点到晚上 11 点)可以正常工作并说出正确的话。

4

2 回答 2

2

尝试这个:

@ECHO OFF &SETLOCAL
set /a HH=0
FOR /f "tokens=1*delims=0" %%a IN ("$0%time:~0,2%") DO SET /a HH=%%b 2>nul
IF %HH% GTR 5 ECHO Alert!
于 2013-07-10T19:28:29.723 回答
2
@ECHO OFF
SETLOCAL
SET testvalues=" 1" " 4" " 5" " 6" "10" "12" "13" "19" "20" "23" "01" "04" "05" "06" "08" " 0" 
FOR %%i IN (%testvalues%) DO CALL :test2 %%i
echo==================================
FOR %%i IN (%testvalues%) DO CALL :test %%i
GOTO :eof
:test
SET value=%~1
SET "HH="
FOR /f "delims=0" %%a IN ("%value:~0,2%") DO SET /a HH=%%a
IF %HH% GTR 5 (ECHO Alert! FOR %1 ) ELSE (ECHO Silent FOR %1 )

GOTO :EOF
:test2
SET value=%~1
SET "HH="

SET /a HH=1%value: =0%
IF %HH% GTR 105 (ECHO Alert! FOR %1 ) ELSE (ECHO Silent FOR %1 )

GOTO :EOF

结果:

Silent FOR " 1" 
Silent FOR " 4" 
Silent FOR " 5" 
Alert! FOR " 6" 
Alert! FOR "10" 
Alert! FOR "12" 
Alert! FOR "13" 
Alert! FOR "19" 
Alert! FOR "20" 
Alert! FOR "23" 
Silent FOR "01" 
Silent FOR "04" 
Silent FOR "05" 
Alert! FOR "06" 
Alert! FOR "08" 
Silent FOR " 0" 
=================================
Silent FOR " 1" 
Silent FOR " 4" 
Silent FOR " 5" 
Alert! FOR " 6" 
Silent FOR "10" 
Alert! FOR "12" 
Alert! FOR "13" 
Alert! FOR "19" 
Silent FOR "20" 
Alert! FOR "23" 
Silent FOR "01" 
Silent FOR "04" 
Silent FOR "05" 
Alert! FOR "06" 
Alert! FOR "08" 
Missing operand.
5 was unexpected at this time.

注意:更正了小时 = 10、20 和 0 的行为

于 2013-07-10T20:02:19.910 回答