Time 如何检查现在的时间是否在AutoIt中的给定时间之间
我正在检查现在的时间是否在13:00和17:00之间。我认为Time 如何检查现在的时间是否在AutoIt中的给定时间之间,time,autoit,Time,Autoit,我正在检查现在的时间是否在13:00和17:00之间。我认为\u Datediff函数(使用\u dateadd()和\u NowTimeCalc())不起作用 是否有一些我缺少的库函数?或者我必须编写一个手动函数来比较@Hour和@min 我正在做这样的事情: Func CheckTime($sStart, $sEnd) $s = StringSplit($sStart, ":") $e = StringSplit($sEnd, ":") $s[1] = Int($s[
\u Datediff
函数(使用\u dateadd()
和\u NowTimeCalc()
)不起作用
是否有一些我缺少的库函数?或者我必须编写一个手动函数来比较@Hour
和@min
我正在做这样的事情:
Func CheckTime($sStart, $sEnd)
$s = StringSplit($sStart, ":")
$e = StringSplit($sEnd, ":")
$s[1] = Int($s[1])
$s[2] = Int($s[2])
$e[1] = Int($e[1])
$e[2] = Int($e[2])
$result = False
If $s[0] <= 0 And $e <= 0 Then
ConsoleWrite("Wrong Time Format")
Exit
EndIf
If $s[1] <= @HOUR And $e[1] >= @HOUR Then
If @HOUR >= $s[1] And @MIN > $s[2] Then
If @HOUR <= $e[1] And @MIN < $e[2] Then
$result = True
EndIf
EndIf
EndIf
Return $result
EndFunc ; ==>CheckTime
#region ;************ Includes ************
#include <Array.au3>
#include <Date.au3>
#endregion ;************ Includes ************
ConsoleWrite(_timeBetween(@HOUR & ':' & @MIN, '10:05', '12:09'))
Func _timeBetween($cTime, $sTime, $eTime)
If Not _DateIsValid('2000/01/01 ' & $cTime) Then Return -1
If Not _DateIsValid('2000/01/01 ' & $sTime) Then Return -2
If Not _DateIsValid('2000/01/01 ' & $eTime) Then Return -3
;~ ConsoleWrite(_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $sTime & ':00') & @CRLF)
;~ ConsoleWrite(_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $eTime & ':00') & @CRLF)
If _DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $sTime & ':00') < 0 And _
_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $eTime & ':00') > 0 Then
Return 1
Else
Return 0
EndIf
EndFunc ; ==>_timeBetween
Func检查时间($sStart,$sEnd)
$s=StringSplit($sStart,“:”)
$e=StringSplit($sEnd,“:”)
$s[1]=Int($s[1])
$s[2]=Int($s[2])
$e[1]=Int($e[1])
$e[2]=Int($e[2])
$result=False
如果$s[0]$s[2],则
如果@HOUR CheckTime
现在,当开始时间<结束时间时,它可以正常工作,但我要寻找的是一些好的方法,而不是手动检查。使用标准用户定义函数(UDF),您可以尝试使用以下方法:
Func CheckTime($sStart, $sEnd)
$s = StringSplit($sStart, ":")
$e = StringSplit($sEnd, ":")
$s[1] = Int($s[1])
$s[2] = Int($s[2])
$e[1] = Int($e[1])
$e[2] = Int($e[2])
$result = False
If $s[0] <= 0 And $e <= 0 Then
ConsoleWrite("Wrong Time Format")
Exit
EndIf
If $s[1] <= @HOUR And $e[1] >= @HOUR Then
If @HOUR >= $s[1] And @MIN > $s[2] Then
If @HOUR <= $e[1] And @MIN < $e[2] Then
$result = True
EndIf
EndIf
EndIf
Return $result
EndFunc ; ==>CheckTime
#region ;************ Includes ************
#include <Array.au3>
#include <Date.au3>
#endregion ;************ Includes ************
ConsoleWrite(_timeBetween(@HOUR & ':' & @MIN, '10:05', '12:09'))
Func _timeBetween($cTime, $sTime, $eTime)
If Not _DateIsValid('2000/01/01 ' & $cTime) Then Return -1
If Not _DateIsValid('2000/01/01 ' & $sTime) Then Return -2
If Not _DateIsValid('2000/01/01 ' & $eTime) Then Return -3
;~ ConsoleWrite(_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $sTime & ':00') & @CRLF)
;~ ConsoleWrite(_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $eTime & ':00') & @CRLF)
If _DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $sTime & ':00') < 0 And _
_DateDiff('s', '2000/01/01 ' & $cTime & ':00', '2000/01/01 ' & $eTime & ':00') > 0 Then
Return 1
Else
Return 0
EndIf
EndFunc ; ==>_timeBetween
#地区;*************包括************
#包括
#包括
#末端区域;*************包括************
控制台写入(_timeBetween(@HOUR&':'&@MIN,'10:05','12:09'))
函数时间间隔($cTime、$TIME、$eTime)
如果日期无效('2000/01/01'和$cTime),则返回-1
如果日期无效('2000/01/01'和$sTime),则返回-2
如果日期无效('2000/01/01'和$eTime),则返回-3
;~ 控制台写入(_DateDiff('s',2000/01/01'和$cTime&':00',2000/01/01'和$sTime&':00')&@CRLF)
;~ 控制台写入(_DateDiff('s',2000/01/01'和$cTime&':00',2000/01/01'和$eTime&':00')&@CRLF)
如果DateDiff('s','2000/01/01'和$cTime&':00','2000/01/01'和$sTime&':00')<0和_
_DateDiff('s','2000/01/01'和$cTime&':00','2000/01/01'和$eTime&':00')>0然后
返回1
其他的
返回0
恩迪夫
EndFunc;==>_时差
对我来说更简单的版本-只需使用hh:mm格式的字符串比较
#include <Date.au3>
Func _timeBetween( $sTime, $eTime)
Return (_NowTime(4) < $eTime) And (_NowTime(4) > $eTime)
EndFunc ; ==>_timeBetween
MsgBox(0, "daytime","is day = " & _timeBetween("08:00"."23:00") )
#包括
函数时间间隔($sTime,$eTime)
返回(_NowTime(4)<$eTime)和(_NowTime(4)>$eTime)
EndFunc;==>_时差
MsgBox(0,“day”,“is day=“&_timeBetween”(“08:00”,“23:00”))
不错,但这不适用于穿越午夜,例如22:00到02:00之间的时间