Explanation of the moderator code on the second floor:
:: 『Second floor』: Moderator code of Budenbuai:
SET /a a=%time:~0,2%*60+%time:~3,2%
if %a% geq 480 if %a% leq 1080 (goto next step)
GOTO :EOF
:next step
..........
The above code (marked in
red) is to take the
hour in the %time% environment variable (obtained by intercepting the string method)
For example: If the time shown in %time% is: 11:15:33.01 (that is: 11 o'clock and 15 minutes), then %time:~0,2% is to take two characters from the offset 0 start in the %time% variable. What is taken is the
hour.
%time:~0,2%*60, multiply the obtained hour by 60 (minutes), because one hour is 60 minutes, so the hour number obtained through the string interception function needs to be converted into the total number of minutes, so it needs to be multiplied by 60 again. Because converting hours to minutes is for the convenience of comparing a certain time range.
+%time:~3,2%, when the hour is obtained and the hour is multiplied by 60 to convert it into minutes, it is not enough, because the
minute number in the %time% variable is also needed, so %time:~3,2% (if the %time% time is: 11:
15:33.01) then it is to take two characters starting from offset 3 (offset is calculated from 0), these two characters are the above (blue marked) "15".
Because the number of hours has been converted into minutes, and then adding the number of minutes in %time%, the total number of minutes of the current time obtained in this way is more accurate.
Converting to the total number of minutes can make it more convenient and simple to use IF for calculation (and can also perform addition and subtraction calculations and other special times or operations on the range of dates based on this principle...).
leq 1080 (marked in green in the above code), here LEQ means less than or equal to. Its help information can be seen by using the IF /? command:
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to
The meaning of the above code refers to: less than or equal to 1080 minutes (18 o'clock: there are 18 hours from 0 o'clock to 6 o'clock in the evening, which is 18 hours * 60 minutes per hour, which is 1080 minutes)
Then use minutes as the basic unit for comparison:
IF the current time is greater than or equal to 480 minutes (that is, 480/60=8 hours, which is 8 o'clock in the morning) and the current time is less than or equal to 1080 minutes (1080/60=18 hours, which is 18 o'clock in the evening), as long as the time range is between these, this is what the building owner requires: if the current time is between 8 o'clock in the morning - 18 o'clock in the evening, execute a certain command...
(Intercepting string knowledge: There is in the help information of SET /?)
(Knowledge of %time%: There is at the end of the help information of SET /? about the dynamic environment variables that can be "called")
(Knowledge of judging size and judgment: There is in the help information of IF /?)
(Knowledge of Goto: There is in the help information of GOTO /?)
For dates, a similar method of converting all to numerical values can also be used to determine the time attributes of a certain file: special applications such as being within a certain date range.
[
Last edited by redtek on 2007-1-26 at 12:10 PM ]